We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
len_if
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
My case:
We should ensure the Values must has value if Enabled is true.
Values
Enabled
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"` }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
My case:
We should ensure the
Values
must has value ifEnabled
is true.If the
Values
is nil, the validator work well, but if theValues
is an empty slice, it can pass the validator.I've read the docs, I think it work as expected:
So, I think we should add a tag like
len_if
?The text was updated successfully, but these errors were encountered: