|
|
|
@ -119,8 +119,17 @@ func (v *Validate) SetTagName(name string) { |
|
|
|
|
v.tagName = name |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// RegisterTagNameFunc registers a function to get another name from the
|
|
|
|
|
// StructField eg. the JSON name
|
|
|
|
|
// RegisterTagNameFunc registers a function to get alternate names for StructFields.
|
|
|
|
|
//
|
|
|
|
|
// 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) { |
|
|
|
|
v.tagNameFunc = fn |
|
|
|
|
v.hasTagNameFunc = true |
|
|
|
|