Merge pull request #406 from frou/doc-registertagnamefunc

Document RegisterTagNameFunc more
pull/414/head
Dean Karn 6 years ago committed by GitHub
commit 9f802bbd9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      validator_instance.go

@ -119,8 +119,17 @@ func (v *Validate) SetTagName(name string) {
v.tagName = name v.tagName = name
} }
// RegisterTagNameFunc registers a function to get another name from the // RegisterTagNameFunc registers a function to get alternate names for StructFields.
// StructField eg. the JSON name //
// eg. to use the names which have been specified for JSON representations of structs, rather than normal Go field names:
//
// validate.RegisterTagNameFunc(func(fld reflect.StructField) string {
// name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
// if name == "-" {
// return ""
// }
// return name
// })
func (v *Validate) RegisterTagNameFunc(fn TagNameFunc) { func (v *Validate) RegisterTagNameFunc(fn TagNameFunc) {
v.tagNameFunc = fn v.tagNameFunc = fn
v.hasTagNameFunc = true v.hasTagNameFunc = true

Loading…
Cancel
Save