|
|
@ -5,7 +5,9 @@ import ( |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
|
"reflect" |
|
|
|
"reflect" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
"unicode/utf8" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// BakedInValidators is the default map of ValidationFunc
|
|
|
|
// BakedInValidators is the default map of ValidationFunc
|
|
|
@ -42,6 +44,38 @@ var BakedInValidators = map[string]Func{ |
|
|
|
"url": isURL, |
|
|
|
"url": isURL, |
|
|
|
"uri": isURI, |
|
|
|
"uri": isURI, |
|
|
|
"base64": isBase64, |
|
|
|
"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 { |
|
|
|
func isNeField(top interface{}, current interface{}, field interface{}, param string) bool { |
|
|
|