-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
My case:
We should ensure the Values must has value if Enabled is true.
struct Foo {
Enabled bool
Values []string `validate:"required_if=Enabled true,dive,oneof=a b c"`
}If the Values is nil, the validator work well, but if the Values is an empty slice, it can pass the validator.
I've read the docs, I think it work as expected:
For slices, maps, pointers, interfaces, channels and functions ensures the value is not nil. For structs ensures value is not the zero value.
So, I think we should add a tag like len_if?
struct Foo {
Enabled bool
Values []string `validate:"len_if=Enabled true 0,dive,oneof=a b c"`
}Metadata
Metadata
Assignees
Labels
No labels