An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
type User struct {
Name string
Cars []Car
}
type Car struct {
ID int
Name string
}
func (v User) Validate() error {
return validation.ValidateStruct(&v,
validation.Field(&v.Name, validation.Required),
validation.Field(&v.Cars, validation.Length(1, 0)), // car's validation is triggered here... But I don't really care... How can I skip it
)
}
func (c Car) Validate() error {
return validation.ValidateStruct(&c,
validation.Field(&c.Name, validation.Required),
)
}
As of the documentation, Car struct implements the Validatable interface. Hence, it will be .Validate() will be called. But what if I want to skip it? Just the validation.Length().
I wanted to validate a struct. For example:
As of the documentation,
Car
struct implements theValidatable
interface. Hence, it will be.Validate()
will be called. But what if I want to skip it? Just thevalidation.Length()
.Thank you so much.