Skip to content

Instantly share code, notes, and snippets.

@apzuk3
Last active October 17, 2022 18:51
Show Gist options
  • Save apzuk3/b7ecfbb22e3fcd638594fe0fb59d3f82 to your computer and use it in GitHub Desktop.
Save apzuk3/b7ecfbb22e3fcd638594fe0fb59d3f82 to your computer and use it in GitHub Desktop.
Validation rules
package main
import "fmt"
type User struct {
Email string `json:"email" validate:"required,email"`
Name string `json:"name" validate:"required,min=2,max=100"`
}
func main() {
u := User{}
err := validate.Validate(a)
fmt.Fatal(err)
}
@virenpawar
Copy link

err := validate.Validate(u)

Small correction.

@tejasa97
Copy link

where is validate got from?

@Alina-dev-front
Copy link

It will throw the error: undeclared name: validate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment