Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
validate
✓ github.com/gobuffalo/validate
Define a struct with custom validation and check for errors.
package main
import (
"github.com/gobuffalo/validate"
"log"
)
type User struct {
Name string `json:"name"`
Age int `json:"age"`
}
func (u *User) Validate() *validate.Errors {
errors := validate.NewErrors()
if u.Name == "" {
errors.Add("name", "name is required")
}
if u.Age < 0 {
errors.Add("age", "age must be positive")
}
return errors
}
func main() {
user := User{Name: "", Age: -1}
errors := user.Validate()
if errors.HasAny() {
log.Println(errors.String())
}
}
Debug
Known issues
gotchaVersion 2.0.4+incompatible indicates a pre-Go-modules release; use v3 or later for proper module support.fixUpgrade to the latest v3 version (github.com/gobuffalo/validate/v3).
affects: 2.0.4+incompatible
Upgrade
Version history
2.0.4+incompatiblelatest on pkg.go.dev
Audit
Dependencies
No dependency data recorded yet.