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 actualTag string
ns string ns string
structNs string structNs string
field string fieldLen int
structField string structfieldLen int
// field string
// structField string
value interface{} value interface{}
param string param string
kind reflect.Kind 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 // Field returns the fields name with the tag name taking precedence over the
// fields actual name. // fields actual name.
func (fe *fieldError) Field() string { 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. // returns the fields actual name from the struct, when able to determine.
func (fe *fieldError) StructField() string { 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 // 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 // Error returns the fieldError's error message
func (fe *fieldError) Error() string { 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, actualTag: tag,
ns: v.str1, ns: v.str1,
structNs: v.str2, structNs: v.str2,
field: fieldName, fieldLen: len(fieldName),
structField: structFieldName, structfieldLen: len(structFieldName),
param: param, param: param,
kind: kind, kind: kind,
}, },
@ -136,8 +136,8 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta
actualTag: tag, actualTag: tag,
ns: v.str1, ns: v.str1,
structNs: v.str2, structNs: v.str2,
field: fieldName, fieldLen: len(fieldName),
structField: structFieldName, structfieldLen: len(structFieldName),
value: fv.Interface(), value: fv.Interface(),
param: param, param: param,
kind: kind, kind: kind,

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

Loading…
Cancel
Save