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
[discussion] How to validate an optional field? #177
How to say if Bar provided then validate it is bigger than e.g. 2 else do not validate as it is optional?
Is my solution the best effort?
I mean if i'm not using validation.When(r.Bar != nil, validation.Required, ...) then it accept 0 value for Bar but that is not my intention!
Consider this struct:
How to say if
Bar
provided then validate it is bigger than e.g. 2 else do not validate as it is optional? Is my solution the best effort? I mean if i'm not usingvalidation.When(r.Bar != nil, validation.Required, ...)
then it accept0
value forBar
but that is not my intention!