@@ -10,10 +10,18 @@ import (
1010 "unicode/utf8"
1111)
1212
13+ // BakedInAliasValidators is a default mapping of a single validationstag that
14+ // defines a common or complex set of validation(s) to simplify
15+ // adding validation to structs. i.e. set key "_ageok" and the tags
16+ // are "gt=0,lte=130" or key "_preferredname" and tags "omitempty,gt=0,lte=60"
17+ var bakedInAliasValidators = map [string ]string {
18+ "iscolor" : "hexcolor|rgb|rgba|hsl|hsla" ,
19+ }
20+
1321// BakedInValidators is the default map of ValidationFunc
1422// you can add, remove or even replace items to suite your needs,
1523// or even disregard and use your own map if so desired.
16- var BakedInValidators = map [string ]Func {
24+ var bakedInValidators = map [string ]Func {
1725 "required" : hasValue ,
1826 "len" : hasLengthOf ,
1927 "min" : hasMinOf ,
@@ -107,15 +115,15 @@ func isSSN(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Va
107115 return false
108116 }
109117
110- return matchesRegex ( sSNRegex , field .String ())
118+ return sSNRegex . MatchString ( field .String ())
111119}
112120
113121func isLongitude (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
114- return matchesRegex ( longitudeRegex , field .String ())
122+ return longitudeRegex . MatchString ( field .String ())
115123}
116124
117125func isLatitude (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
118- return matchesRegex ( latitudeRegex , field .String ())
126+ return latitudeRegex . MatchString ( field .String ())
119127}
120128
121129func isDataURI (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
@@ -126,7 +134,7 @@ func isDataURI(v *Validate, topStruct reflect.Value, currentStructOrField reflec
126134 return false
127135 }
128136
129- if ! matchesRegex ( dataURIRegex , uri [0 ]) {
137+ if ! dataURIRegex . MatchString ( uri [0 ]) {
130138 return false
131139 }
132140
@@ -141,31 +149,31 @@ func hasMultiByteCharacter(v *Validate, topStruct reflect.Value, currentStructOr
141149 return true
142150 }
143151
144- return matchesRegex ( multibyteRegex , field .String ())
152+ return multibyteRegex . MatchString ( field .String ())
145153}
146154
147155func isPrintableASCII (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
148- return matchesRegex ( printableASCIIRegex , field .String ())
156+ return printableASCIIRegex . MatchString ( field .String ())
149157}
150158
151159func isASCII (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
152- return matchesRegex ( aSCIIRegex , field .String ())
160+ return aSCIIRegex . MatchString ( field .String ())
153161}
154162
155163func isUUID5 (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
156- return matchesRegex ( uUID5Regex , field .String ())
164+ return uUID5Regex . MatchString ( field .String ())
157165}
158166
159167func isUUID4 (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
160- return matchesRegex ( uUID4Regex , field .String ())
168+ return uUID4Regex . MatchString ( field .String ())
161169}
162170
163171func isUUID3 (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
164- return matchesRegex ( uUID3Regex , field .String ())
172+ return uUID3Regex . MatchString ( field .String ())
165173}
166174
167175func isUUID (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
168- return matchesRegex ( uUIDRegex , field .String ())
176+ return uUIDRegex . MatchString ( field .String ())
169177}
170178
171179func isISBN (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
@@ -176,7 +184,7 @@ func isISBN13(v *Validate, topStruct reflect.Value, currentStructOrField reflect
176184
177185 s := strings .Replace (strings .Replace (field .String (), "-" , "" , 4 ), " " , "" , 4 )
178186
179- if ! matchesRegex ( iSBN13Regex , s ) {
187+ if ! iSBN13Regex . MatchString ( s ) {
180188 return false
181189 }
182190
@@ -200,7 +208,7 @@ func isISBN10(v *Validate, topStruct reflect.Value, currentStructOrField reflect
200208
201209 s := strings .Replace (strings .Replace (field .String (), "-" , "" , 3 ), " " , "" , 3 )
202210
203- if ! matchesRegex ( iSBN10Regex , s ) {
211+ if ! iSBN10Regex . MatchString ( s ) {
204212 return false
205213 }
206214
@@ -617,7 +625,7 @@ func isEq(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Val
617625}
618626
619627func isBase64 (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
620- return matchesRegex ( base64Regex , field .String ())
628+ return base64Regex . MatchString ( field .String ())
621629}
622630
623631func isURI (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
@@ -655,47 +663,47 @@ func isURL(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Va
655663}
656664
657665func isEmail (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
658- return matchesRegex ( emailRegex , field .String ())
666+ return emailRegex . MatchString ( field .String ())
659667}
660668
661669func isHsla (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
662- return matchesRegex ( hslaRegex , field .String ())
670+ return hslaRegex . MatchString ( field .String ())
663671}
664672
665673func isHsl (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
666- return matchesRegex ( hslRegex , field .String ())
674+ return hslRegex . MatchString ( field .String ())
667675}
668676
669677func isRgba (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
670- return matchesRegex ( rgbaRegex , field .String ())
678+ return rgbaRegex . MatchString ( field .String ())
671679}
672680
673681func isRgb (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
674- return matchesRegex ( rgbRegex , field .String ())
682+ return rgbRegex . MatchString ( field .String ())
675683}
676684
677685func isHexcolor (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
678- return matchesRegex ( hexcolorRegex , field .String ())
686+ return hexcolorRegex . MatchString ( field .String ())
679687}
680688
681689func isHexadecimal (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
682- return matchesRegex ( hexadecimalRegex , field .String ())
690+ return hexadecimalRegex . MatchString ( field .String ())
683691}
684692
685693func isNumber (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
686- return matchesRegex ( numberRegex , field .String ())
694+ return numberRegex . MatchString ( field .String ())
687695}
688696
689697func isNumeric (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
690- return matchesRegex ( numericRegex , field .String ())
698+ return numericRegex . MatchString ( field .String ())
691699}
692700
693701func isAlphanum (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
694- return matchesRegex ( alphaNumericRegex , field .String ())
702+ return alphaNumericRegex . MatchString ( field .String ())
695703}
696704
697705func isAlpha (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
698- return matchesRegex ( alphaRegex , field .String ())
706+ return alphaRegex . MatchString ( field .String ())
699707}
700708
701709func hasValue (v * Validate , topStruct reflect.Value , currentStructOrField reflect.Value , field reflect.Value , fieldType reflect.Type , fieldKind reflect.Kind , param string ) bool {
0 commit comments