|
|
@ -5,43 +5,77 @@ 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
|
|
|
|
// you can add, remove or even replace items to suite your needs,
|
|
|
|
// you can add, remove or even replace items to suite your needs,
|
|
|
|
// or even disregard and use your own map if so desired.
|
|
|
|
// or even disregard and use your own map if so desired.
|
|
|
|
var BakedInValidators = map[string]Func{ |
|
|
|
var BakedInValidators = map[string]Func{ |
|
|
|
"required": hasValue, |
|
|
|
"required": hasValue, |
|
|
|
"len": hasLengthOf, |
|
|
|
"len": hasLengthOf, |
|
|
|
"min": hasMinOf, |
|
|
|
"min": hasMinOf, |
|
|
|
"max": hasMaxOf, |
|
|
|
"max": hasMaxOf, |
|
|
|
"eq": isEq, |
|
|
|
"eq": isEq, |
|
|
|
"ne": isNe, |
|
|
|
"ne": isNe, |
|
|
|
"lt": isLt, |
|
|
|
"lt": isLt, |
|
|
|
"lte": isLte, |
|
|
|
"lte": isLte, |
|
|
|
"gt": isGt, |
|
|
|
"gt": isGt, |
|
|
|
"gte": isGte, |
|
|
|
"gte": isGte, |
|
|
|
"eqfield": isEqField, |
|
|
|
"eqfield": isEqField, |
|
|
|
"nefield": isNeField, |
|
|
|
"nefield": isNeField, |
|
|
|
"gtefield": isGteField, |
|
|
|
"gtefield": isGteField, |
|
|
|
"gtfield": isGtField, |
|
|
|
"gtfield": isGtField, |
|
|
|
"ltefield": isLteField, |
|
|
|
"ltefield": isLteField, |
|
|
|
"ltfield": isLtField, |
|
|
|
"ltfield": isLtField, |
|
|
|
"alpha": isAlpha, |
|
|
|
"alpha": isAlpha, |
|
|
|
"alphanum": isAlphanum, |
|
|
|
"alphanum": isAlphanum, |
|
|
|
"numeric": isNumeric, |
|
|
|
"numeric": isNumeric, |
|
|
|
"number": isNumber, |
|
|
|
"number": isNumber, |
|
|
|
"hexadecimal": isHexadecimal, |
|
|
|
"hexadecimal": isHexadecimal, |
|
|
|
"hexcolor": isHexcolor, |
|
|
|
"hexcolor": isHexcolor, |
|
|
|
"rgb": isRgb, |
|
|
|
"rgb": isRgb, |
|
|
|
"rgba": isRgba, |
|
|
|
"rgba": isRgba, |
|
|
|
"hsl": isHsl, |
|
|
|
"hsl": isHsl, |
|
|
|
"hsla": isHsla, |
|
|
|
"hsla": isHsla, |
|
|
|
"email": isEmail, |
|
|
|
"email": isEmail, |
|
|
|
"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 { |
|
|
|