Merge pull request #211 from joeybloggs/v8-development

Add minor optimization for structonly & nostructlevel checks
pull/212/head
Dean Karn 9 years ago
commit ba623db026
  1. 13
      util.go
  2. 6
      validator.go

@ -271,15 +271,22 @@ func (v *Validate) parseTagsRecursive(cTag *cachedTag, tag, fieldName, alias str
} }
} }
if t == diveTag { switch t {
case diveTag:
cTag.diveTag = tag cTag.diveTag = tag
tVals := &tagVals{tagVals: [][]string{{t}}} tVals := &tagVals{tagVals: [][]string{{t}}}
cTag.tags = append(cTag.tags, tVals) cTag.tags = append(cTag.tags, tVals)
return true return true
}
if t == omitempty { case omitempty:
cTag.isOmitEmpty = true cTag.isOmitEmpty = true
case structOnlyTag:
cTag.isStructOnly = true
case noStructLevelTag:
cTag.isNoStructLevel = true
} }
// if a pipe character is needed within the param you must use the utf8Pipe representation "0x7C" // if a pipe character is needed within the param you must use the utf8Pipe representation "0x7C"

@ -49,6 +49,8 @@ var (
type cachedTag struct { type cachedTag struct {
isOmitEmpty bool isOmitEmpty bool
isNoStructLevel bool
isStructOnly bool
diveTag string diveTag string
tags []*tagVals tags []*tagVals
} }
@ -597,11 +599,11 @@ func (v *Validate) traverseField(topStruct reflect.Value, currentStruct reflect.
if typ != timeType { if typ != timeType {
if strings.Contains(tag, noStructLevelTag) { if cTag.isNoStructLevel {
return return
} }
v.tranverseStruct(topStruct, current, current, errPrefix+name+".", errs, false, partial, exclude, includeExclude, strings.Contains(tag, structOnlyTag)) v.tranverseStruct(topStruct, current, current, errPrefix+name+".", errs, false, partial, exclude, includeExclude, cTag.isStructOnly)
return return
} }
} }

Loading…
Cancel
Save