-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
We should have the ability to attach a global validator method on a struct.
Suggestion
A single dumb validator method for validating the struct. Automatically called before all field validators.
type Foo struct {
IsBraw bool
Age int
}
func (f *Foo) Validate() error {
if f.IsBraw && f.Age >= 120 {
return errors.New("Braw, you too old.")
}
return nil
}
Thoughts
- Should there be support for only one of these validators? Is there a case where one would want to have multiple methods?
- Is "Validate" dangerous to use? I.e. when validating nested structures, one could accidentally have a struct referenced with the function "Validate". This could cause strange unpredictable errors... So might be better use the convention/automatically discover methods named "Validate_{Name}" or "ValidateGlobal{Name}".