why pass the Field names, they already belong to the namespaces...

pull/256/head
joeybloggs 8 years ago
parent ea09db9292
commit b2c8f66e7b
  1. 14
      errors.go
  2. 8
      struct_level.go
  3. 20
      validator.go

@ -132,8 +132,10 @@ type fieldError struct {
actualTag string
ns string
structNs string
field string
structField string
fieldLen int
structfieldLen int
// field string
// structField string
value interface{}
param string
kind reflect.Kind
@ -166,12 +168,14 @@ func (fe *fieldError) StructNamespace() string {
// Field returns the fields name with the tag name taking precedence over the
// fields actual name.
func (fe *fieldError) Field() string {
return fe.field
// return fe.field
return fe.ns[len(fe.ns)-fe.fieldLen:]
}
// returns the fields actual name from the struct, when able to determine.
func (fe *fieldError) StructField() string {
return fe.structField
// return fe.structField
return fe.structNs[len(fe.structNs)-fe.structfieldLen:]
}
// Value returns the actual fields value in case needed for creating the error
@ -198,5 +202,5 @@ func (fe *fieldError) Type() reflect.Type {
// Error returns the fieldError's error message
func (fe *fieldError) Error() string {
return fmt.Sprintf(fieldErrMsg, fe.ns, fe.field, fe.tag)
return fmt.Sprintf(fieldErrMsg, fe.ns, fe.Field(), fe.tag)
}

@ -121,8 +121,8 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta
actualTag: tag,
ns: v.str1,
structNs: v.str2,
field: fieldName,
structField: structFieldName,
fieldLen: len(fieldName),
structfieldLen: len(structFieldName),
param: param,
kind: kind,
},
@ -136,8 +136,8 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta
actualTag: tag,
ns: v.str1,
structNs: v.str2,
field: fieldName,
structField: structFieldName,
fieldLen: len(fieldName),
structfieldLen: len(structFieldName),
value: fv.Interface(),
param: param,
kind: kind,

@ -117,8 +117,8 @@ func (v *validate) traverseField(parent reflect.Value, current reflect.Value, ns
actualTag: ct.tag,
ns: v.str1,
structNs: v.str2,
field: cf.altName,
structField: cf.name,
fieldLen: len(cf.altName),
structfieldLen: len(cf.name),
param: ct.param,
kind: kind,
},
@ -133,8 +133,8 @@ func (v *validate) traverseField(parent reflect.Value, current reflect.Value, ns
actualTag: ct.tag,
ns: v.str1,
structNs: v.str2,
field: cf.altName,
structField: cf.name,
fieldLen: len(cf.altName),
structfieldLen: len(cf.name),
value: current.Interface(),
param: ct.param,
kind: kind,
@ -327,8 +327,8 @@ OUTER:
actualTag: ct.actualAliasTag,
ns: v.str1,
structNs: v.str2,
field: cf.altName,
structField: cf.name,
fieldLen: len(cf.altName),
structfieldLen: len(cf.name),
value: current.Interface(),
param: ct.param,
kind: kind,
@ -346,8 +346,8 @@ OUTER:
actualTag: tVal,
ns: v.str1,
structNs: v.str2,
field: cf.altName,
structField: cf.name,
fieldLen: len(cf.altName),
structfieldLen: len(cf.name),
value: current.Interface(),
param: ct.param,
kind: kind,
@ -385,8 +385,8 @@ OUTER:
actualTag: ct.tag,
ns: v.str1,
structNs: v.str2,
field: cf.altName,
structField: cf.name,
fieldLen: len(cf.altName),
structfieldLen: len(cf.name),
value: current.Interface(),
param: ct.param,
kind: kind,

Loading…
Cancel
Save