The Validate function could be generated with code representing the gator struct tags. For example:
type BigStruct struct {
Required string `gator:”nonzero”`
Email string `gator:”email”`
DayOfWeek int `gator:”gte(0) | lt(7)”`
}
would generate:
func (b *BigStruct) Validate() error {
return gator.New().Add(
gator.NewField("Required", b.Required, gator.Nonzero()),
gator.NewField("Email", b.Email, gator.Email()),
gator.NewField("DayOfWeek", b.DayOfWeek, gator.Gte(0)),
gator.NewField("DayOfWeek", b.DayOfWeek, gator.Lt(7)),
).Validate()
}
This would have all the advantages of compile time validation.
The Validate function could be generated with code representing the gator struct tags. For example:
would generate:
This would have all the advantages of compile time validation.