diff --git a/cache.go b/cache.go index 86de914..aabe17f 100644 --- a/cache.go +++ b/cache.go @@ -153,7 +153,13 @@ func (v *Validate) extractStructCache(current reflect.Value, sName string) *cStr ctag = new(cTag) } - cs.fields[i] = &cField{idx: i, name: fld.Name, altName: customName, cTags: ctag, namesEqual: fld.Name == customName} + cs.fields[i] = &cField{ + idx: i, + name: fld.Name, + altName: customName, + cTags: ctag, + namesEqual: fld.Name == customName, + } } v.structCache.Set(typ, cs) diff --git a/errors.go b/errors.go index b279b92..0e4489c 100644 --- a/errors.go +++ b/errors.go @@ -132,14 +132,12 @@ type fieldError struct { actualTag string ns string structNs string - fieldLen int - structfieldLen int - // field string - // structField string - value interface{} - param string - kind reflect.Kind - typ reflect.Type + fieldLen uint8 + structfieldLen uint8 + value interface{} + param string + kind reflect.Kind + typ reflect.Type } // Tag returns the validation tag that failed. @@ -169,13 +167,13 @@ func (fe *fieldError) StructNamespace() string { // fields actual name. func (fe *fieldError) Field() string { // return fe.field - return fe.ns[len(fe.ns)-fe.fieldLen:] + return fe.ns[len(fe.ns)-int(fe.fieldLen):] } // returns the fields actual name from the struct, when able to determine. func (fe *fieldError) StructField() string { // return fe.structField - return fe.structNs[len(fe.structNs)-fe.structfieldLen:] + return fe.structNs[len(fe.structNs)-int(fe.structfieldLen):] } // Value returns the actual fields value in case needed for creating the error diff --git a/struct_level.go b/struct_level.go index aaaf327..d12d7e9 100644 --- a/struct_level.go +++ b/struct_level.go @@ -121,8 +121,8 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta actualTag: tag, ns: v.str1, structNs: v.str2, - fieldLen: len(fieldName), - structfieldLen: len(structFieldName), + fieldLen: uint8(len(fieldName)), + structfieldLen: uint8(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, - fieldLen: len(fieldName), - structfieldLen: len(structFieldName), + fieldLen: uint8(len(fieldName)), + structfieldLen: uint8(len(structFieldName)), value: fv.Interface(), param: param, kind: kind, diff --git a/validator.go b/validator.go index c42e6db..2119152 100644 --- a/validator.go +++ b/validator.go @@ -117,8 +117,8 @@ func (v *validate) traverseField(parent reflect.Value, current reflect.Value, ns actualTag: ct.tag, ns: v.str1, structNs: v.str2, - fieldLen: len(cf.altName), - structfieldLen: len(cf.name), + fieldLen: uint8(len(cf.altName)), + structfieldLen: uint8(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, - fieldLen: len(cf.altName), - structfieldLen: len(cf.name), + fieldLen: uint8(len(cf.altName)), + structfieldLen: uint8(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, - fieldLen: len(cf.altName), - structfieldLen: len(cf.name), + fieldLen: uint8(len(cf.altName)), + structfieldLen: uint8(len(cf.name)), value: current.Interface(), param: ct.param, kind: kind, @@ -346,8 +346,8 @@ OUTER: actualTag: tVal, ns: v.str1, structNs: v.str2, - fieldLen: len(cf.altName), - structfieldLen: len(cf.name), + fieldLen: uint8(len(cf.altName)), + structfieldLen: uint8(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, - fieldLen: len(cf.altName), - structfieldLen: len(cf.name), + fieldLen: uint8(len(cf.altName)), + structfieldLen: uint8(len(cf.name)), value: current.Interface(), param: ct.param, kind: kind,