validator icon indicating copy to clipboard operation
validator copied to clipboard

Add zerotonil tag

Open ceebydith opened this issue 3 years ago • 1 comments

Enhance feature with zerotonil

Allows conditional validation, for example if field pointer has zero value of type then field value will be assign as nil. Sometime it needs nil value rather then zero value in future used of struct on other codes like omitempty tag for ignoring on database field, so no need set to nil manually.

NOTE: only valid for field pointer and struct passed with pointer.

  • [x] Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

ceebydith avatar Nov 09 '22 00:11 ceebydith

Coverage Status

Coverage increased (+0.006%) to 74.189% when pulling 1336d063812122bd5b73c0167678c0dccda417b7 on ceebydith:zerotonil into c7e0172e0fd176bdc521afb5186818a7db6b77ac on go-playground:master.

coveralls avatar Nov 09 '22 00:11 coveralls

One tenant of validator is that it does not mutate any of the validate-able data, this may e a good addition, if not already present, to this package https://github.com/go-playground/mold

deankarn avatar Mar 19 '23 18:03 deankarn