|
|
|
@ -5,7 +5,9 @@ import ( |
|
|
|
|
"net/url" |
|
|
|
|
"reflect" |
|
|
|
|
"strconv" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
"unicode/utf8" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// BakedInValidators is the default map of ValidationFunc
|
|
|
|
@ -42,6 +44,38 @@ var BakedInValidators = map[string]Func{ |
|
|
|
|
"url": isURL, |
|
|
|
|
"uri": isURI, |
|
|
|
|
"base64": isBase64, |
|
|
|
|
"contains": contains, |
|
|
|
|
"containsany": containsAny, |
|
|
|
|
"containsrune": containsRune, |
|
|
|
|
"excludes": excludes, |
|
|
|
|
"excludesall": excludesAll, |
|
|
|
|
"excludesrune": excludesRune, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func excludesRune(top interface{}, current interface{}, field interface{}, param string) bool { |
|
|
|
|
return !containsRune(top, current, field, param) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func excludesAll(top interface{}, current interface{}, field interface{}, param string) bool { |
|
|
|
|
return !containsAny(top, current, field, param) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func excludes(top interface{}, current interface{}, field interface{}, param string) bool { |
|
|
|
|
return !contains(top, current, field, param) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func containsRune(top interface{}, current interface{}, field interface{}, param string) bool { |
|
|
|
|
r, _ := utf8.DecodeRuneInString(param) |
|
|
|
|
|
|
|
|
|
return strings.ContainsRune(field.(string), r) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func containsAny(top interface{}, current interface{}, field interface{}, param string) bool { |
|
|
|
|
return strings.ContainsAny(field.(string), param) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func contains(top interface{}, current interface{}, field interface{}, param string) bool { |
|
|
|
|
return strings.Contains(field.(string), param) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isNeField(top interface{}, current interface{}, field interface{}, param string) bool { |
|
|
|
|