validate
validate copied to clipboard
Feature request: Override validation rule within a scene
I have defined some custom scenes so that I can validate my struct in different ways.
func (User) ConfigValidation(v *validate.Validation) {
v.WithScenes(validate.SValues{
Create: []string{"Kind", "Name", "Birthday"},
Update: []string{"ID", "Kind", "Name", "Birthday"},
})
}
I would love it if I could specify different rules for each of these scene fields.
For example, when I create a user I want to validate that the user has left ID empty. It is not enough to skip validation, I must make sure they have not filled it out.
func (User) ConfigValidation(v *validate.Validation) {
v.WithScenes(validate.SValues{
Create: []string{"ID:'empty'", "Kind", "Name", "Birthday"},
Update: []string{"ID", "Kind", "Name", "Birthday"},
})
}
If no rule is provided inside the SValue, then it should fall back to the rule defined on the struct tags.