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

Executing rules when "When" condition is not matched #107

Closed samber closed 4 years ago

samber commented 4 years ago

Adding the Else case to conditional validations.

Example:


validation.Field(&a.Unit, validation.When(a.Quantity != "", validation.Required).Else(validation.Nil))

README includes the Nil rule added by #106

coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling baef62fdb241f01c66410b9f4ad8b64801029f92 on samber:feat-else-rules into f6ac6c4a9c44e58d830291066150ec95fd9205f3 on go-ozzo:master.

qiangxue commented 4 years ago

This is great! Thank you for your contribution!