MSP-8299 vendor update
This commit is contained in:
1 parent
c8e4a014a0
commit
59d487646c
607 files changed
+48706
-13176
No files matched your search
+34
-8
@@ -116,7 +116,7 @@ func (v *validate) traverseField(ctx context.Context, parent reflect.Value, curr
|
||||
|
||||
if ct.hasTag {
|
||||
if kind == reflect.Invalid {
|
||||
v.str1 = string(append(ns, cf.altName...))
|
||||
v.str1 = appendAltName(ns, cf.altName)
|
||||
if v.v.hasTagNameFunc {
|
||||
v.str2 = string(append(structNs, cf.name...))
|
||||
} else {
|
||||
@@ -138,7 +138,7 @@ func (v *validate) traverseField(ctx context.Context, parent reflect.Value, curr
|
||||
return
|
||||
}
|
||||
|
||||
v.str1 = string(append(ns, cf.altName...))
|
||||
v.str1 = appendAltName(ns, cf.altName)
|
||||
if v.v.hasTagNameFunc {
|
||||
v.str2 = string(append(structNs, cf.name...))
|
||||
} else {
|
||||
@@ -192,7 +192,9 @@ OUTER:
|
||||
// VarWithField - this allows for validating against each field within the struct against a specific value
|
||||
// pretty handy in certain situations
|
||||
if len(cf.name) > 0 {
|
||||
ns = append(append(ns, cf.altName...), '.')
|
||||
if len(cf.altName) > 0 {
|
||||
ns = append(append(ns, cf.altName...), '.')
|
||||
}
|
||||
structNs = append(append(structNs, cf.name...), '.')
|
||||
}
|
||||
v.validateStruct(ctx, parent, current, typ, ns, structNs, ct)
|
||||
@@ -218,7 +220,9 @@ OUTER:
|
||||
// VarWithField - this allows for validating against each field within the struct against a specific value
|
||||
// pretty handy in certain situations
|
||||
if len(cf.name) > 0 {
|
||||
ns = append(append(ns, cf.altName...), '.')
|
||||
if len(cf.altName) > 0 {
|
||||
ns = append(append(ns, cf.altName...), '.')
|
||||
}
|
||||
structNs = append(append(structNs, cf.name...), '.')
|
||||
}
|
||||
|
||||
@@ -266,7 +270,7 @@ OUTER:
|
||||
return
|
||||
}
|
||||
default:
|
||||
if v.fldIsPointer && field.Interface() == nil {
|
||||
if v.fldIsPointer && getValue(field) == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -318,7 +322,7 @@ OUTER:
|
||||
reusableCF := &cField{}
|
||||
|
||||
for _, key := range current.MapKeys() {
|
||||
pv = fmt.Sprintf("%v", key.Interface())
|
||||
pv = fmt.Sprintf("%v", key)
|
||||
|
||||
v.misc = append(v.misc[0:0], cf.name...)
|
||||
v.misc = append(v.misc, '[')
|
||||
@@ -343,6 +347,18 @@ OUTER:
|
||||
// can be nil when just keys being validated
|
||||
if ct.next != nil {
|
||||
v.traverseField(ctx, parent, current.MapIndex(key), ns, structNs, reusableCF, ct.next)
|
||||
} else {
|
||||
// Struct fallback when map values are structs
|
||||
val := current.MapIndex(key)
|
||||
switch val.Kind() {
|
||||
case reflect.Ptr:
|
||||
if val.Elem().Kind() == reflect.Struct {
|
||||
// Dive into the struct so its own tags run
|
||||
v.traverseField(ctx, parent, val, ns, structNs, reusableCF, nil)
|
||||
}
|
||||
case reflect.Struct:
|
||||
v.traverseField(ctx, parent, val, ns, structNs, reusableCF, nil)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
v.traverseField(ctx, parent, current.MapIndex(key), ns, structNs, reusableCF, ct)
|
||||
@@ -403,7 +419,7 @@ OUTER:
|
||||
|
||||
if ct.isBlockEnd || ct.next == nil {
|
||||
// if we get here, no valid 'or' value and no more tags
|
||||
v.str1 = string(append(ns, cf.altName...))
|
||||
v.str1 = appendAltName(ns, cf.altName)
|
||||
|
||||
if v.v.hasTagNameFunc {
|
||||
v.str2 = string(append(structNs, cf.name...))
|
||||
@@ -462,7 +478,7 @@ OUTER:
|
||||
v.ct = ct
|
||||
|
||||
if !ct.fn(ctx, v) {
|
||||
v.str1 = string(append(ns, cf.altName...))
|
||||
v.str1 = appendAltName(ns, cf.altName)
|
||||
|
||||
if v.v.hasTagNameFunc {
|
||||
v.str2 = string(append(structNs, cf.name...))
|
||||
@@ -493,6 +509,16 @@ OUTER:
|
||||
}
|
||||
}
|
||||
|
||||
func appendAltName(ns []byte, altName string) string {
|
||||
if len(altName) > 0 {
|
||||
return string(append(ns, altName...))
|
||||
}
|
||||
if n := len(ns); n > 0 && ns[n-1] == '.' {
|
||||
return string(ns[:n-1])
|
||||
}
|
||||
return string(ns)
|
||||
}
|
||||
|
||||
func getValue(val reflect.Value) interface{} {
|
||||
if val.CanInterface() {
|
||||
return val.Interface()
|
||||
|
||||
Reference in new issue
Block a user