type User struct {
Name string `json:"name"`
Email string `json:"email"`
Message string `json:"message"`
}
func (u User) Valid() (bool, validator.Errors) {
return validator.ByJSON(u, validator.Validators{
"name": validator.StringRequire(u.Name, validator.Shorter(2)),
"email": validator.StringRequire(u.Email, validator.Email()),
"message": validator.StringOption(u.Message, validator.Longer(10)),
})
}
func main() {
user := User{
Message: "Oops!",
}
valid, errs := user.Valid()
// validation: false map[email:field required message:too short name:field required]
fmt.Printf("validation: %v %v\n", valid, errs)
}
-
Notifications
You must be signed in to change notification settings - Fork 0
srce/validator
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published