go-ozzo / ozzo-validation

An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
MIT License
3.73k stars 224 forks source link

Unexpected interaction of numeric zero with Min(...) #62

Closed frou closed 5 years ago

frou commented 5 years ago

Is it intended behaviour that the following does not return an error?

validation.Validate(0, validation.Min(10))

I know we can use validation.Required but 0 is definitely < 10 also :)

frou commented 5 years ago

Thinking about this more, I guess the general philosophy is that zero-values in the Go sense are always considered valid unless we explicitly indicate that they are not?

qiangxue commented 5 years ago

Yes. 0 is considered as an empty value. You can add a required rule to ensure a value is entered.

frou commented 5 years ago

Thank you. I starred a bunch of Go validation repos and finally am getting around to evaluating them. Your "normal code" approach is cool!

screenshot 2018-10-24 at 17 59 03