mirror of
https://github.com/Fishwaldo/validator.git
synced 2025-03-17 12:41:33 +00:00
Merge pull request #212 from go-playground/v8-development
Add minor optimization for structonly & nostructlevel checks
This commit is contained in:
commit
d776d3eb2e
2 changed files with 17 additions and 8 deletions
13
util.go
13
util.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
|
||||
tVals := &tagVals{tagVals: [][]string{{t}}}
|
||||
cTag.tags = append(cTag.tags, tVals)
|
||||
return true
|
||||
}
|
||||
|
||||
if t == omitempty {
|
||||
case omitempty:
|
||||
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"
|
||||
|
|
12
validator.go
12
validator.go
|
@ -48,9 +48,11 @@ var (
|
|||
)
|
||||
|
||||
type cachedTag struct {
|
||||
isOmitEmpty bool
|
||||
diveTag string
|
||||
tags []*tagVals
|
||||
isOmitEmpty bool
|
||||
isNoStructLevel bool
|
||||
isStructOnly bool
|
||||
diveTag string
|
||||
tags []*tagVals
|
||||
}
|
||||
|
||||
type tagVals struct {
|
||||
|
@ -597,11 +599,11 @@ func (v *Validate) traverseField(topStruct reflect.Value, currentStruct reflect.
|
|||
|
||||
if typ != timeType {
|
||||
|
||||
if strings.Contains(tag, noStructLevelTag) {
|
||||
if cTag.isNoStructLevel {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue