|
|
@ -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 |
|
|
|