|
|
@ -141,18 +141,24 @@ var ( |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var oneofValCache = map[string][]string{} |
|
|
|
var oneofValsCache = map[string][]string{} |
|
|
|
var oneofValCacheLock = sync.Mutex{} |
|
|
|
var oneofValsCacheRWLock = sync.RWMutex{} |
|
|
|
|
|
|
|
|
|
|
|
func isOneOf(fl FieldLevel) bool { |
|
|
|
func parseOneOfParam2(s string) []string { |
|
|
|
param := fl.Param() |
|
|
|
oneofValsCacheRWLock.RLock() |
|
|
|
oneofValCacheLock.Lock() |
|
|
|
vals, ok := oneofValsCache[s] |
|
|
|
vals, ok := oneofValCache[param] |
|
|
|
oneofValsCacheRWLock.RUnlock() |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
vals = strings.Fields(param) |
|
|
|
oneofValsCacheRWLock.Lock() |
|
|
|
oneofValCache[param] = vals |
|
|
|
vals = strings.Fields(s) |
|
|
|
|
|
|
|
oneofValsCache[s] = vals |
|
|
|
|
|
|
|
oneofValsCacheRWLock.Unlock() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return vals |
|
|
|
} |
|
|
|
} |
|
|
|
oneofValCacheLock.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
func isOneOf(fl FieldLevel) bool { |
|
|
|
|
|
|
|
vals := parseOneOfParam2(fl.Param()) |
|
|
|
|
|
|
|
|
|
|
|
field := fl.Field() |
|
|
|
field := fl.Field() |
|
|
|
|
|
|
|
|
|
|
|