From dcdba454d7cce61032b4a52eac40883704b26239 Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Fri, 5 Aug 2016 23:21:09 -0400 Subject: [PATCH] some variable cleanup --- struct_level.go | 19 +++++++++++-------- validator.go | 11 ++--------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/struct_level.go b/struct_level.go index e721841..4e294e7 100644 --- a/struct_level.go +++ b/struct_level.go @@ -105,8 +105,11 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta structFieldName = fieldName } - v.slNs = append(v.slNs, fieldName...) - v.slStructNs = append(v.slStructNs, structFieldName...) + // v.slNs = append(v.slNs, fieldName...) + // v.slStructNs = append(v.slStructNs, structFieldName...) + + v.ns = append(v.ns, fieldName...) + v.actualNs = append(v.actualNs, structFieldName...) switch kind { case reflect.Invalid: @@ -115,8 +118,8 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta &fieldError{ tag: tag, actualTag: tag, - ns: string(v.slNs), - structNs: string(v.slStructNs), + ns: string(v.ns), + structNs: string(v.actualNs), field: fieldName, structField: structFieldName, // param: "", @@ -130,8 +133,8 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta &fieldError{ tag: tag, actualTag: tag, - ns: string(v.slNs), - structNs: string(v.slStructNs), + ns: string(v.ns), + structNs: string(v.actualNs), field: fieldName, structField: structFieldName, value: fv.Interface(), @@ -153,8 +156,8 @@ func (v *validate) ReportValidationErrors(relativeNamespace, relativeStructNames for i := 0; i < len(errs); i++ { err = errs[i].(*fieldError) - err.ns = string(append(append(v.slNs, relativeNamespace...), err.ns...)) - err.structNs = string(append(append(v.slStructNs, relativeStructNamespace...), err.structNs...)) + err.ns = string(append(append(v.ns, relativeNamespace...), err.ns...)) + err.structNs = string(append(append(v.actualNs, relativeStructNamespace...), err.structNs...)) v.errs = append(v.errs, err) } diff --git a/validator.go b/validator.go index 1998281..7476c76 100644 --- a/validator.go +++ b/validator.go @@ -6,11 +6,6 @@ import ( "strconv" ) -const ( - arrayIndexFieldName = "%s" + leftBracket + "%d" + rightBracket - mapIndexFieldName = "%s" + leftBracket + "%v" + rightBracket -) - // per validate contruct type validate struct { v *Validate @@ -26,8 +21,6 @@ type validate struct { // StructLevel & FieldLevel fields slflParent reflect.Value slCurrent reflect.Value - slNs []byte - slStructNs []byte flField reflect.Value flParam string } @@ -75,8 +68,8 @@ func (v *validate) validateStruct(parent reflect.Value, current reflect.Value, t v.slflParent = parent v.slCurrent = current - v.slNs = ns - v.slStructNs = structNs + v.ns = ns + v.actualNs = structNs cs.fn(v) }