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
Validation Errors should use JSON tag values as the error keys when marshalling. #2
Related to https://github.com/go-ozzo/ozzo-validation/pull/1, when marshalling validation.Errors It would be great if we can detect struct fields with the json tag and use that as the key in the map for validation.Errors.
A option for doing this is to convert validation.Errors to a struct that contains two fields Errs map[string]err & ErrsJSON map[string]string. Errs map key contains the Struct field name and ErrsJSON map key contains the Struct json tag value.
Another option would be to use a custom field tag e.g. validation that is checked for and if specified we use it as the map key for the error message. This isn't specifically meant to be used when marshalling json.
Related to https://github.com/go-ozzo/ozzo-validation/pull/1, when marshalling
validation.Errors
It would be great if we can detect struct fields with thejson
tag and use that as the key in the map forvalidation.Errors
.A option for doing this is to convert
validation.Errors
to a struct that contains two fieldsErrs map[string]err
&ErrsJSON map[string]string
.Errs
map key contains the Struct field name andErrsJSON
map key contains the Struct json tag value.Another option would be to use a custom field tag e.g.
validation
that is checked for and if specified we use it as the map key for the error message. This isn't specifically meant to be used when marshalling json.@qiangxue thoughts?