|
|
@ -520,23 +520,8 @@ func (v *Validate) VarCtx(ctx context.Context, field interface{}, tag string) (e |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// find cached tag
|
|
|
|
ctag := v.fetchCacheTag(tag) |
|
|
|
ctag, ok := v.tagCache.Get(tag) |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
v.tagCache.lock.Lock() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// could have been multiple trying to access, but once first is done this ensures tag
|
|
|
|
|
|
|
|
// isn't parsed again.
|
|
|
|
|
|
|
|
ctag, ok = v.tagCache.Get(tag) |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
ctag, _ = v.parseFieldTagsRecursive(tag, "", "", false) |
|
|
|
|
|
|
|
v.tagCache.Set(tag, ctag) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
v.tagCache.lock.Unlock() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val := reflect.ValueOf(field) |
|
|
|
val := reflect.ValueOf(field) |
|
|
|
|
|
|
|
|
|
|
|
vd := v.pool.Get().(*validate) |
|
|
|
vd := v.pool.Get().(*validate) |
|
|
|
vd.top = val |
|
|
|
vd.top = val |
|
|
|
vd.isPartial = false |
|
|
|
vd.isPartial = false |
|
|
@ -546,9 +531,7 @@ func (v *Validate) VarCtx(ctx context.Context, field interface{}, tag string) (e |
|
|
|
err = vd.errs |
|
|
|
err = vd.errs |
|
|
|
vd.errs = nil |
|
|
|
vd.errs = nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
v.pool.Put(vd) |
|
|
|
v.pool.Put(vd) |
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -589,36 +572,17 @@ func (v *Validate) VarWithValueCtx(ctx context.Context, field interface{}, other |
|
|
|
if len(tag) == 0 || tag == skipValidationTag { |
|
|
|
if len(tag) == 0 || tag == skipValidationTag { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ctag := v.fetchCacheTag(tag) |
|
|
|
// find cached tag
|
|
|
|
|
|
|
|
ctag, ok := v.tagCache.Get(tag) |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
v.tagCache.lock.Lock() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// could have been multiple trying to access, but once first is done this ensures tag
|
|
|
|
|
|
|
|
// isn't parsed again.
|
|
|
|
|
|
|
|
ctag, ok = v.tagCache.Get(tag) |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
ctag, _ = v.parseFieldTagsRecursive(tag, "", "", false) |
|
|
|
|
|
|
|
v.tagCache.Set(tag, ctag) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
v.tagCache.lock.Unlock() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
otherVal := reflect.ValueOf(other) |
|
|
|
otherVal := reflect.ValueOf(other) |
|
|
|
|
|
|
|
|
|
|
|
vd := v.pool.Get().(*validate) |
|
|
|
vd := v.pool.Get().(*validate) |
|
|
|
vd.top = otherVal |
|
|
|
vd.top = otherVal |
|
|
|
vd.isPartial = false |
|
|
|
vd.isPartial = false |
|
|
|
|
|
|
|
|
|
|
|
vd.traverseField(ctx, otherVal, reflect.ValueOf(field), vd.ns[0:0], vd.actualNs[0:0], defaultCField, ctag) |
|
|
|
vd.traverseField(ctx, otherVal, reflect.ValueOf(field), vd.ns[0:0], vd.actualNs[0:0], defaultCField, ctag) |
|
|
|
|
|
|
|
|
|
|
|
if len(vd.errs) > 0 { |
|
|
|
if len(vd.errs) > 0 { |
|
|
|
err = vd.errs |
|
|
|
err = vd.errs |
|
|
|
vd.errs = nil |
|
|
|
vd.errs = nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
v.pool.Put(vd) |
|
|
|
v.pool.Put(vd) |
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|