some variable cleanup

pull/256/head
joeybloggs 8 years ago
parent d9bfef9fe0
commit dcdba454d7
  1. 19
      struct_level.go
  2. 11
      validator.go

@ -105,8 +105,11 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta
structFieldName = fieldName structFieldName = fieldName
} }
v.slNs = append(v.slNs, fieldName...) // v.slNs = append(v.slNs, fieldName...)
v.slStructNs = append(v.slStructNs, structFieldName...) // v.slStructNs = append(v.slStructNs, structFieldName...)
v.ns = append(v.ns, fieldName...)
v.actualNs = append(v.actualNs, structFieldName...)
switch kind { switch kind {
case reflect.Invalid: case reflect.Invalid:
@ -115,8 +118,8 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta
&fieldError{ &fieldError{
tag: tag, tag: tag,
actualTag: tag, actualTag: tag,
ns: string(v.slNs), ns: string(v.ns),
structNs: string(v.slStructNs), structNs: string(v.actualNs),
field: fieldName, field: fieldName,
structField: structFieldName, structField: structFieldName,
// param: "", // param: "",
@ -130,8 +133,8 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta
&fieldError{ &fieldError{
tag: tag, tag: tag,
actualTag: tag, actualTag: tag,
ns: string(v.slNs), ns: string(v.ns),
structNs: string(v.slStructNs), structNs: string(v.actualNs),
field: fieldName, field: fieldName,
structField: structFieldName, structField: structFieldName,
value: fv.Interface(), value: fv.Interface(),
@ -153,8 +156,8 @@ func (v *validate) ReportValidationErrors(relativeNamespace, relativeStructNames
for i := 0; i < len(errs); i++ { for i := 0; i < len(errs); i++ {
err = errs[i].(*fieldError) err = errs[i].(*fieldError)
err.ns = string(append(append(v.slNs, relativeNamespace...), err.ns...)) err.ns = string(append(append(v.ns, relativeNamespace...), err.ns...))
err.structNs = string(append(append(v.slStructNs, relativeStructNamespace...), err.structNs...)) err.structNs = string(append(append(v.actualNs, relativeStructNamespace...), err.structNs...))
v.errs = append(v.errs, err) v.errs = append(v.errs, err)
} }

@ -6,11 +6,6 @@ import (
"strconv" "strconv"
) )
const (
arrayIndexFieldName = "%s" + leftBracket + "%d" + rightBracket
mapIndexFieldName = "%s" + leftBracket + "%v" + rightBracket
)
// per validate contruct // per validate contruct
type validate struct { type validate struct {
v *Validate v *Validate
@ -26,8 +21,6 @@ type validate struct {
// StructLevel & FieldLevel fields // StructLevel & FieldLevel fields
slflParent reflect.Value slflParent reflect.Value
slCurrent reflect.Value slCurrent reflect.Value
slNs []byte
slStructNs []byte
flField reflect.Value flField reflect.Value
flParam string flParam string
} }
@ -75,8 +68,8 @@ func (v *validate) validateStruct(parent reflect.Value, current reflect.Value, t
v.slflParent = parent v.slflParent = parent
v.slCurrent = current v.slCurrent = current
v.slNs = ns v.ns = ns
v.slStructNs = structNs v.actualNs = structNs
cs.fn(v) cs.fn(v)
} }

Loading…
Cancel
Save