Browse Source

Update go-playground validator

Update the go-playground validator to support "startswith" and
"endswith" validators to be used to validate images used for production.
See the example in policy.example.yaml for how this would be used.

Bug: T215319
Change-Id: Ie4362184bdb19399c667b4180b4bef32c2198063
Tyler Cipriani 5 months ago
parent
commit
15715357cf

+ 11
- 4
Gopkg.lock View File

@@ -48,6 +48,14 @@
48 48
   version = "v0.16.0"
49 49
 
50 50
 [[projects]]
51
+  digest = "1:c41a98ec16b8b053f921ad36d510f552321d6c86d2cd46d15b0ef3b85e67dd5f"
52
+  name = "github.com/leodido/go-urn"
53
+  packages = ["."]
54
+  pruneopts = "NUT"
55
+  revision = "70078a794e8ea4b497ba7c19a78cd60f90ccf0f4"
56
+  version = "v1.1.0"
57
+
58
+[[projects]]
51 59
   branch = "v2"
52 60
   digest = "1:981e58364d2283b4f5931e7a1c4a2c3c09f1336bacf2d64c63ca9356fd9a0099"
53 61
   name = "github.com/pborman/getopt"
@@ -80,12 +88,12 @@
80 88
   version = "v0.1.0"
81 89
 
82 90
 [[projects]]
83
-  digest = "1:e396e0963c85b8a2b437e419b55aa0169a212eb06a7c88fd2bf16e5e5cfce2f2"
91
+  digest = "1:46be8f82a48108fd6e61e3214933c5678246533c270a687be501d788c8ad0a1b"
84 92
   name = "gopkg.in/go-playground/validator.v9"
85 93
   packages = ["."]
86 94
   pruneopts = "NUT"
87
-  revision = "1b8c8e19cd250435025214492d9a08411d760fdd"
88
-  version = "v9.12.0"
95
+  revision = "884d31b8cad6a1ec877f2400d555924cea03bbea"
96
+  version = "v9.29.0"
89 97
 
90 98
 [[projects]]
91 99
   branch = "v2"
@@ -105,7 +113,6 @@
105 113
     "github.com/stretchr/testify/assert",
106 114
     "github.com/utahta/go-openuri",
107 115
     "gopkg.in/go-playground/validator.v9",
108
-    "gopkg.in/yaml.v2",
109 116
   ]
110 117
   solver-name = "gps-cdcl"
111 118
   solver-version = 1

+ 1
- 1
Gopkg.toml View File

@@ -15,7 +15,7 @@
15 15
 
16 16
 [[constraint]]
17 17
   name = "gopkg.in/go-playground/validator.v9"
18
-  version = "9.12.0"
18
+  version = "9.29.0"
19 19
 
20 20
 [[constraint]]
21 21
   branch = "v2"

+ 2
- 2
blubber.example.yaml View File

@@ -1,6 +1,6 @@
1 1
 ---
2 2
 version: v3
3
-base: debian:jessie
3
+base: docker-registry.wikimedia.org/wikimedia-stretch:latest
4 4
 apt:
5 5
   packages: [libjpeg, libyaml]
6 6
 python:
@@ -42,7 +42,7 @@ variants:
42 42
       env: production
43 43
 
44 44
   production:
45
-    base: debian:jessie-slim
45
+    base: docker-registry.wikimedia.org/wikimedia-stretch:latest
46 46
     node:
47 47
       env: production
48 48
     copies: [prep]

+ 6
- 2
policy.example.yaml View File

@@ -1,5 +1,9 @@
1 1
 enforcements:
2
-  - path: variants.production.base
3
-    rule: oneof=debian:jessie debian:jessie-slim
2
+  - path: base
3
+    rule: oneof=docker-registry.wikimedia.org/wikimedia-stretch:latest docker-registry.wikimedia.org/wikimedia-jessie:latest
4 4
   - path: variants.production.runs.insecurely
5 5
     rule: isfalse
6
+  - path: variants.test.base
7
+    rule: omitempty,startswith=docker-registry.wikimedia.org
8
+  - path: variants.production.base
9
+    rule: omitempty,startswith=docker-registry.wikimedia.org

+ 1670
- 0
vendor/github.com/leodido/go-urn/machine.go
File diff suppressed because it is too large
View File


+ 63
- 0
vendor/github.com/leodido/go-urn/urn.go View File

@@ -0,0 +1,63 @@
1
+package urn
2
+
3
+import (
4
+	"strings"
5
+)
6
+
7
+// URN represents an Uniform Resource Name.
8
+//
9
+// The general form represented is:
10
+//
11
+//	urn:<id>:<ss>
12
+//
13
+// Details at https://tools.ietf.org/html/rfc2141.
14
+type URN struct {
15
+	prefix string // Static prefix. Equal to "urn" when empty.
16
+	ID     string // Namespace identifier
17
+	SS     string // Namespace specific string
18
+	norm   string // Normalized namespace specific string
19
+}
20
+
21
+// Normalize turns the receiving URN into its norm version.
22
+//
23
+// Which means: lowercase prefix, lowercase namespace identifier, and immutate namespace specific string chars (except <hex> tokens which are lowercased).
24
+func (u *URN) Normalize() *URN {
25
+	return &URN{
26
+		prefix: "urn",
27
+		ID:     strings.ToLower(u.ID),
28
+		SS:     u.norm,
29
+	}
30
+}
31
+
32
+// Equal checks the lexical equivalence of the current URN with another one.
33
+func (u *URN) Equal(x *URN) bool {
34
+	return *u.Normalize() == *x.Normalize()
35
+}
36
+
37
+// String reassembles the URN into a valid URN string.
38
+//
39
+// This requires both ID and SS fields to be non-empty.
40
+// Otherwise it returns an empty string.
41
+//
42
+// Default URN prefix is "urn".
43
+func (u *URN) String() string {
44
+	var res string
45
+	if u.ID != "" && u.SS != "" {
46
+		if u.prefix == "" {
47
+			res += "urn"
48
+		}
49
+		res += u.prefix + ":" + u.ID + ":" + u.SS
50
+	}
51
+
52
+	return res
53
+}
54
+
55
+// Parse is responsible to create an URN instance from a byte array matching the correct URN syntax.
56
+func Parse(u []byte) (*URN, bool) {
57
+	urn, err := NewMachine().Parse(u)
58
+	if err != nil {
59
+		return nil, false
60
+	}
61
+
62
+	return urn, true
63
+}

+ 506
- 90
vendor/gopkg.in/go-playground/validator.v9/baked_in.go View File

@@ -1,16 +1,21 @@
1 1
 package validator
2 2
 
3 3
 import (
4
+	"bytes"
4 5
 	"context"
6
+	"crypto/sha256"
5 7
 	"fmt"
6 8
 	"net"
7 9
 	"net/url"
10
+	"os"
8 11
 	"reflect"
9 12
 	"strconv"
10 13
 	"strings"
11 14
 	"sync"
12 15
 	"time"
13 16
 	"unicode/utf8"
17
+
18
+	urn "github.com/leodido/go-urn"
14 19
 )
15 20
 
16 21
 // Func accepts a FieldLevel interface for all validation needs. The return
@@ -57,87 +62,109 @@ var (
57 62
 	// you can add, remove or even replace items to suite your needs,
58 63
 	// or even disregard and use your own map if so desired.
59 64
 	bakedInValidators = map[string]Func{
60
-		"required":         hasValue,
61
-		"isdefault":        isDefault,
62
-		"len":              hasLengthOf,
63
-		"min":              hasMinOf,
64
-		"max":              hasMaxOf,
65
-		"eq":               isEq,
66
-		"ne":               isNe,
67
-		"lt":               isLt,
68
-		"lte":              isLte,
69
-		"gt":               isGt,
70
-		"gte":              isGte,
71
-		"eqfield":          isEqField,
72
-		"eqcsfield":        isEqCrossStructField,
73
-		"necsfield":        isNeCrossStructField,
74
-		"gtcsfield":        isGtCrossStructField,
75
-		"gtecsfield":       isGteCrossStructField,
76
-		"ltcsfield":        isLtCrossStructField,
77
-		"ltecsfield":       isLteCrossStructField,
78
-		"nefield":          isNeField,
79
-		"gtefield":         isGteField,
80
-		"gtfield":          isGtField,
81
-		"ltefield":         isLteField,
82
-		"ltfield":          isLtField,
83
-		"alpha":            isAlpha,
84
-		"alphanum":         isAlphanum,
85
-		"alphaunicode":     isAlphaUnicode,
86
-		"alphanumunicode":  isAlphanumUnicode,
87
-		"numeric":          isNumeric,
88
-		"number":           isNumber,
89
-		"hexadecimal":      isHexadecimal,
90
-		"hexcolor":         isHEXColor,
91
-		"rgb":              isRGB,
92
-		"rgba":             isRGBA,
93
-		"hsl":              isHSL,
94
-		"hsla":             isHSLA,
95
-		"email":            isEmail,
96
-		"url":              isURL,
97
-		"uri":              isURI,
98
-		"base64":           isBase64,
99
-		"contains":         contains,
100
-		"containsany":      containsAny,
101
-		"containsrune":     containsRune,
102
-		"excludes":         excludes,
103
-		"excludesall":      excludesAll,
104
-		"excludesrune":     excludesRune,
105
-		"isbn":             isISBN,
106
-		"isbn10":           isISBN10,
107
-		"isbn13":           isISBN13,
108
-		"uuid":             isUUID,
109
-		"uuid3":            isUUID3,
110
-		"uuid4":            isUUID4,
111
-		"uuid5":            isUUID5,
112
-		"ascii":            isASCII,
113
-		"printascii":       isPrintableASCII,
114
-		"multibyte":        hasMultiByteCharacter,
115
-		"datauri":          isDataURI,
116
-		"latitude":         isLatitude,
117
-		"longitude":        isLongitude,
118
-		"ssn":              isSSN,
119
-		"ipv4":             isIPv4,
120
-		"ipv6":             isIPv6,
121
-		"ip":               isIP,
122
-		"cidrv4":           isCIDRv4,
123
-		"cidrv6":           isCIDRv6,
124
-		"cidr":             isCIDR,
125
-		"tcp4_addr":        isTCP4AddrResolvable,
126
-		"tcp6_addr":        isTCP6AddrResolvable,
127
-		"tcp_addr":         isTCPAddrResolvable,
128
-		"udp4_addr":        isUDP4AddrResolvable,
129
-		"udp6_addr":        isUDP6AddrResolvable,
130
-		"udp_addr":         isUDPAddrResolvable,
131
-		"ip4_addr":         isIP4AddrResolvable,
132
-		"ip6_addr":         isIP6AddrResolvable,
133
-		"ip_addr":          isIPAddrResolvable,
134
-		"unix_addr":        isUnixAddrResolvable,
135
-		"mac":              isMAC,
136
-		"hostname":         isHostnameRFC952,  // RFC 952
137
-		"hostname_rfc1123": isHostnameRFC1123, // RFC 1123
138
-		"fqdn":             isFQDN,
139
-		"unique":           isUnique,
140
-		"oneof":            isOneOf,
65
+		"required":             hasValue,
66
+		"required_with":        requiredWith,
67
+		"required_with_all":    requiredWithAll,
68
+		"required_without":     requiredWithout,
69
+		"required_without_all": requiredWithoutAll,
70
+		"isdefault":            isDefault,
71
+		"len":                  hasLengthOf,
72
+		"min":                  hasMinOf,
73
+		"max":                  hasMaxOf,
74
+		"eq":                   isEq,
75
+		"ne":                   isNe,
76
+		"lt":                   isLt,
77
+		"lte":                  isLte,
78
+		"gt":                   isGt,
79
+		"gte":                  isGte,
80
+		"eqfield":              isEqField,
81
+		"eqcsfield":            isEqCrossStructField,
82
+		"necsfield":            isNeCrossStructField,
83
+		"gtcsfield":            isGtCrossStructField,
84
+		"gtecsfield":           isGteCrossStructField,
85
+		"ltcsfield":            isLtCrossStructField,
86
+		"ltecsfield":           isLteCrossStructField,
87
+		"nefield":              isNeField,
88
+		"gtefield":             isGteField,
89
+		"gtfield":              isGtField,
90
+		"ltefield":             isLteField,
91
+		"ltfield":              isLtField,
92
+		"fieldcontains":        fieldContains,
93
+		"fieldexcludes":        fieldExcludes,
94
+		"alpha":                isAlpha,
95
+		"alphanum":             isAlphanum,
96
+		"alphaunicode":         isAlphaUnicode,
97
+		"alphanumunicode":      isAlphanumUnicode,
98
+		"numeric":              isNumeric,
99
+		"number":               isNumber,
100
+		"hexadecimal":          isHexadecimal,
101
+		"hexcolor":             isHEXColor,
102
+		"rgb":                  isRGB,
103
+		"rgba":                 isRGBA,
104
+		"hsl":                  isHSL,
105
+		"hsla":                 isHSLA,
106
+		"email":                isEmail,
107
+		"url":                  isURL,
108
+		"uri":                  isURI,
109
+		"urn_rfc2141":          isUrnRFC2141, // RFC 2141
110
+		"file":                 isFile,
111
+		"base64":               isBase64,
112
+		"base64url":            isBase64URL,
113
+		"contains":             contains,
114
+		"containsany":          containsAny,
115
+		"containsrune":         containsRune,
116
+		"excludes":             excludes,
117
+		"excludesall":          excludesAll,
118
+		"excludesrune":         excludesRune,
119
+		"startswith":           startsWith,
120
+		"endswith":             endsWith,
121
+		"isbn":                 isISBN,
122
+		"isbn10":               isISBN10,
123
+		"isbn13":               isISBN13,
124
+		"eth_addr":             isEthereumAddress,
125
+		"btc_addr":             isBitcoinAddress,
126
+		"btc_addr_bech32":      isBitcoinBech32Address,
127
+		"uuid":                 isUUID,
128
+		"uuid3":                isUUID3,
129
+		"uuid4":                isUUID4,
130
+		"uuid5":                isUUID5,
131
+		"uuid_rfc4122":         isUUIDRFC4122,
132
+		"uuid3_rfc4122":        isUUID3RFC4122,
133
+		"uuid4_rfc4122":        isUUID4RFC4122,
134
+		"uuid5_rfc4122":        isUUID5RFC4122,
135
+		"ascii":                isASCII,
136
+		"printascii":           isPrintableASCII,
137
+		"multibyte":            hasMultiByteCharacter,
138
+		"datauri":              isDataURI,
139
+		"latitude":             isLatitude,
140
+		"longitude":            isLongitude,
141
+		"ssn":                  isSSN,
142
+		"ipv4":                 isIPv4,
143
+		"ipv6":                 isIPv6,
144
+		"ip":                   isIP,
145
+		"cidrv4":               isCIDRv4,
146
+		"cidrv6":               isCIDRv6,
147
+		"cidr":                 isCIDR,
148
+		"tcp4_addr":            isTCP4AddrResolvable,
149
+		"tcp6_addr":            isTCP6AddrResolvable,
150
+		"tcp_addr":             isTCPAddrResolvable,
151
+		"udp4_addr":            isUDP4AddrResolvable,
152
+		"udp6_addr":            isUDP6AddrResolvable,
153
+		"udp_addr":             isUDPAddrResolvable,
154
+		"ip4_addr":             isIP4AddrResolvable,
155
+		"ip6_addr":             isIP6AddrResolvable,
156
+		"ip_addr":              isIPAddrResolvable,
157
+		"unix_addr":            isUnixAddrResolvable,
158
+		"mac":                  isMAC,
159
+		"hostname":             isHostnameRFC952,  // RFC 952
160
+		"hostname_rfc1123":     isHostnameRFC1123, // RFC 1123
161
+		"fqdn":                 isFQDN,
162
+		"unique":               isUnique,
163
+		"oneof":                isOneOf,
164
+		"html":                 isHTML,
165
+		"html_encoded":         isHTMLEncoded,
166
+		"url_encoded":          isURLEncoded,
167
+		"dir":                  isDir,
141 168
 	}
142 169
 )
143 170
 
@@ -157,6 +184,18 @@ func parseOneOfParam2(s string) []string {
157 184
 	return vals
158 185
 }
159 186
 
187
+func isURLEncoded(fl FieldLevel) bool {
188
+	return uRLEncodedRegex.MatchString(fl.Field().String())
189
+}
190
+
191
+func isHTMLEncoded(fl FieldLevel) bool {
192
+	return hTMLEncodedRegex.MatchString(fl.Field().String())
193
+}
194
+
195
+func isHTML(fl FieldLevel) bool {
196
+	return hTMLRegex.MatchString(fl.Field().String())
197
+}
198
+
160 199
 func isOneOf(fl FieldLevel) bool {
161 200
 	vals := parseOneOfParam2(fl.Param())
162 201
 
@@ -181,7 +220,7 @@ func isOneOf(fl FieldLevel) bool {
181 220
 	return false
182 221
 }
183 222
 
184
-// isUnique is the validation function for validating if each array|slice element is unique
223
+// isUnique is the validation function for validating if each array|slice|map value is unique
185 224
 func isUnique(fl FieldLevel) bool {
186 225
 
187 226
 	field := fl.Field()
@@ -189,12 +228,19 @@ func isUnique(fl FieldLevel) bool {
189 228
 
190 229
 	switch field.Kind() {
191 230
 	case reflect.Slice, reflect.Array:
192
-		m := reflect.MakeMap(reflect.MapOf(fl.Field().Type().Elem(), v.Type()))
231
+		m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type()))
193 232
 
194 233
 		for i := 0; i < field.Len(); i++ {
195 234
 			m.SetMapIndex(field.Index(i), v)
196 235
 		}
197 236
 		return field.Len() == m.Len()
237
+	case reflect.Map:
238
+		m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type()))
239
+
240
+		for _, k := range field.MapKeys() {
241
+			m.SetMapIndex(field.MapIndex(k), v)
242
+		}
243
+		return field.Len() == m.Len()
198 244
 	default:
199 245
 		panic(fmt.Sprintf("Bad field type %T", field.Interface()))
200 246
 	}
@@ -270,12 +316,48 @@ func isSSN(fl FieldLevel) bool {
270 316
 
271 317
 // IsLongitude is the validation function for validating if the field's value is a valid longitude coordinate.
272 318
 func isLongitude(fl FieldLevel) bool {
273
-	return longitudeRegex.MatchString(fl.Field().String())
319
+	field := fl.Field()
320
+
321
+	var v string
322
+	switch field.Kind() {
323
+	case reflect.String:
324
+		v = field.String()
325
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
326
+		v = strconv.FormatInt(field.Int(), 10)
327
+	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
328
+		v = strconv.FormatUint(field.Uint(), 10)
329
+	case reflect.Float32:
330
+		v = strconv.FormatFloat(field.Float(), 'f', -1, 32)
331
+	case reflect.Float64:
332
+		v = strconv.FormatFloat(field.Float(), 'f', -1, 64)
333
+	default:
334
+		panic(fmt.Sprintf("Bad field type %T", field.Interface()))
335
+	}
336
+
337
+	return longitudeRegex.MatchString(v)
274 338
 }
275 339
 
276 340
 // IsLatitude is the validation function for validating if the field's value is a valid latitude coordinate.
277 341
 func isLatitude(fl FieldLevel) bool {
278
-	return latitudeRegex.MatchString(fl.Field().String())
342
+	field := fl.Field()
343
+
344
+	var v string
345
+	switch field.Kind() {
346
+	case reflect.String:
347
+		v = field.String()
348
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
349
+		v = strconv.FormatInt(field.Int(), 10)
350
+	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
351
+		v = strconv.FormatUint(field.Uint(), 10)
352
+	case reflect.Float32:
353
+		v = strconv.FormatFloat(field.Float(), 'f', -1, 32)
354
+	case reflect.Float64:
355
+		v = strconv.FormatFloat(field.Float(), 'f', -1, 64)
356
+	default:
357
+		panic(fmt.Sprintf("Bad field type %T", field.Interface()))
358
+	}
359
+
360
+	return latitudeRegex.MatchString(v)
279 361
 }
280 362
 
281 363
 // IsDataURI is the validation function for validating if the field's value is a valid data URI.
@@ -336,6 +418,26 @@ func isUUID(fl FieldLevel) bool {
336 418
 	return uUIDRegex.MatchString(fl.Field().String())
337 419
 }
338 420
 
421
+// IsUUID5RFC4122 is the validation function for validating if the field's value is a valid RFC4122 v5 UUID.
422
+func isUUID5RFC4122(fl FieldLevel) bool {
423
+	return uUID5RFC4122Regex.MatchString(fl.Field().String())
424
+}
425
+
426
+// IsUUID4RFC4122 is the validation function for validating if the field's value is a valid RFC4122 v4 UUID.
427
+func isUUID4RFC4122(fl FieldLevel) bool {
428
+	return uUID4RFC4122Regex.MatchString(fl.Field().String())
429
+}
430
+
431
+// IsUUID3RFC4122 is the validation function for validating if the field's value is a valid RFC4122 v3 UUID.
432
+func isUUID3RFC4122(fl FieldLevel) bool {
433
+	return uUID3RFC4122Regex.MatchString(fl.Field().String())
434
+}
435
+
436
+// IsUUIDRFC4122 is the validation function for validating if the field's value is a valid RFC4122 UUID of any version.
437
+func isUUIDRFC4122(fl FieldLevel) bool {
438
+	return uUIDRFC4122Regex.MatchString(fl.Field().String())
439
+}
440
+
339 441
 // IsISBN is the validation function for validating if the field's value is a valid v10 or v13 ISBN.
340 442
 func isISBN(fl FieldLevel) bool {
341 443
 	return isISBN10(fl) || isISBN13(fl)
@@ -387,6 +489,140 @@ func isISBN10(fl FieldLevel) bool {
387 489
 	return checksum%11 == 0
388 490
 }
389 491
 
492
+// IsEthereumAddress is the validation function for validating if the field's value is a valid ethereum address based currently only on the format
493
+func isEthereumAddress(fl FieldLevel) bool {
494
+	address := fl.Field().String()
495
+
496
+	if !ethAddressRegex.MatchString(address) {
497
+		return false
498
+	}
499
+
500
+	if ethaddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
501
+		return true
502
+	}
503
+
504
+	// checksum validation is blocked by https://github.com/golang/crypto/pull/28
505
+
506
+	return true
507
+}
508
+
509
+// IsBitcoinAddress is the validation function for validating if the field's value is a valid btc address
510
+func isBitcoinAddress(fl FieldLevel) bool {
511
+	address := fl.Field().String()
512
+
513
+	if !btcAddressRegex.MatchString(address) {
514
+		return false
515
+	}
516
+
517
+	alphabet := []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
518
+
519
+	decode := [25]byte{}
520
+
521
+	for _, n := range []byte(address) {
522
+		d := bytes.IndexByte(alphabet, n)
523
+
524
+		for i := 24; i >= 0; i-- {
525
+			d += 58 * int(decode[i])
526
+			decode[i] = byte(d % 256)
527
+			d /= 256
528
+		}
529
+	}
530
+
531
+	h := sha256.New()
532
+	_, _ = h.Write(decode[:21])
533
+	d := h.Sum([]byte{})
534
+	h = sha256.New()
535
+	_, _ = h.Write(d)
536
+
537
+	validchecksum := [4]byte{}
538
+	computedchecksum := [4]byte{}
539
+
540
+	copy(computedchecksum[:], h.Sum(d[:0]))
541
+	copy(validchecksum[:], decode[21:])
542
+
543
+	return validchecksum == computedchecksum
544
+}
545
+
546
+// IsBitcoinBech32Address is the validation function for validating if the field's value is a valid bech32 btc address
547
+func isBitcoinBech32Address(fl FieldLevel) bool {
548
+	address := fl.Field().String()
549
+
550
+	if !btcLowerAddressRegexBech32.MatchString(address) && !btcUpperAddressRegexBech32.MatchString(address) {
551
+		return false
552
+	}
553
+
554
+	am := len(address) % 8
555
+
556
+	if am == 0 || am == 3 || am == 5 {
557
+		return false
558
+	}
559
+
560
+	address = strings.ToLower(address)
561
+
562
+	alphabet := "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
563
+
564
+	hr := []int{3, 3, 0, 2, 3} // the human readable part will always be bc
565
+	addr := address[3:]
566
+	dp := make([]int, 0, len(addr))
567
+
568
+	for _, c := range addr {
569
+		dp = append(dp, strings.IndexRune(alphabet, c))
570
+	}
571
+
572
+	ver := dp[0]
573
+
574
+	if ver < 0 || ver > 16 {
575
+		return false
576
+	}
577
+
578
+	if ver == 0 {
579
+		if len(address) != 42 && len(address) != 62 {
580
+			return false
581
+		}
582
+	}
583
+
584
+	values := append(hr, dp...)
585
+
586
+	GEN := []int{0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3}
587
+
588
+	p := 1
589
+
590
+	for _, v := range values {
591
+		b := p >> 25
592
+		p = (p&0x1ffffff)<<5 ^ v
593
+
594
+		for i := 0; i < 5; i++ {
595
+			if (b>>uint(i))&1 == 1 {
596
+				p ^= GEN[i]
597
+			}
598
+		}
599
+	}
600
+
601
+	if p != 1 {
602
+		return false
603
+	}
604
+
605
+	b := uint(0)
606
+	acc := 0
607
+	mv := (1 << 5) - 1
608
+	var sw []int
609
+
610
+	for _, v := range dp[1 : len(dp)-6] {
611
+		acc = (acc << 5) | v
612
+		b += 5
613
+		for b >= 8 {
614
+			b -= 8
615
+			sw = append(sw, (acc>>b)&mv)
616
+		}
617
+	}
618
+
619
+	if len(sw) < 2 || len(sw) > 40 {
620
+		return false
621
+	}
622
+
623
+	return true
624
+}
625
+
390 626
 // ExcludesRune is the validation function for validating that the field's value does not contain the rune specified within the param.
391 627
 func excludesRune(fl FieldLevel) bool {
392 628
 	return !containsRune(fl)
@@ -420,6 +656,41 @@ func contains(fl FieldLevel) bool {
420 656
 	return strings.Contains(fl.Field().String(), fl.Param())
421 657
 }
422 658
 
659
+// StartsWith is the validation function for validating that the field's value starts with the text specified within the param.
660
+func startsWith(fl FieldLevel) bool {
661
+	return strings.HasPrefix(fl.Field().String(), fl.Param())
662
+}
663
+
664
+// EndsWith is the validation function for validating that the field's value ends with the text specified within the param.
665
+func endsWith(fl FieldLevel) bool {
666
+	return strings.HasSuffix(fl.Field().String(), fl.Param())
667
+}
668
+
669
+// FieldContains is the validation function for validating if the current field's value contains the field specified by the param's value.
670
+func fieldContains(fl FieldLevel) bool {
671
+	field := fl.Field()
672
+
673
+	currentField, _, ok := fl.GetStructFieldOK()
674
+
675
+	if !ok {
676
+		return false
677
+	}
678
+
679
+	return strings.Contains(field.String(), currentField.String())
680
+}
681
+
682
+// FieldExcludes is the validation function for validating if the current field's value excludes the field specified by the param's value.
683
+func fieldExcludes(fl FieldLevel) bool {
684
+	field := fl.Field()
685
+
686
+	currentField, _, ok := fl.GetStructFieldOK()
687
+	if !ok {
688
+		return true
689
+	}
690
+
691
+	return !strings.Contains(field.String(), currentField.String())
692
+}
693
+
423 694
 // IsNeField is the validation function for validating if the current field's value is not equal to the field specified by the param's value.
424 695
 func isNeField(fl FieldLevel) bool {
425 696
 
@@ -845,6 +1116,11 @@ func isBase64(fl FieldLevel) bool {
845 1116
 	return base64Regex.MatchString(fl.Field().String())
846 1117
 }
847 1118
 
1119
+// IsBase64URL is the validation function for validating if the current field's value is a valid base64 URL safe string.
1120
+func isBase64URL(fl FieldLevel) bool {
1121
+	return base64URLRegex.MatchString(fl.Field().String())
1122
+}
1123
+
848 1124
 // IsURI is the validation function for validating if the current field's value is a valid URI.
849 1125
 func isURI(fl FieldLevel) bool {
850 1126
 
@@ -908,6 +1184,41 @@ func isURL(fl FieldLevel) bool {
908 1184
 	panic(fmt.Sprintf("Bad field type %T", field.Interface()))
909 1185
 }
910 1186
 
1187
+// isUrnRFC2141 is the validation function for validating if the current field's value is a valid URN as per RFC 2141.
1188
+func isUrnRFC2141(fl FieldLevel) bool {
1189
+	field := fl.Field()
1190
+
1191
+	switch field.Kind() {
1192
+
1193
+	case reflect.String:
1194
+
1195
+		str := field.String()
1196
+
1197
+		_, match := urn.Parse([]byte(str))
1198
+
1199
+		return match
1200
+	}
1201
+
1202
+	panic(fmt.Sprintf("Bad field type %T", field.Interface()))
1203
+}
1204
+
1205
+// IsFile is the validation function for validating if the current field's value is a valid file path.
1206
+func isFile(fl FieldLevel) bool {
1207
+	field := fl.Field()
1208
+
1209
+	switch field.Kind() {
1210
+	case reflect.String:
1211
+		fileInfo, err := os.Stat(field.String())
1212
+		if err != nil {
1213
+			return false
1214
+		}
1215
+
1216
+		return !fileInfo.IsDir()
1217
+	}
1218
+
1219
+	panic(fmt.Sprintf("Bad field type %T", field.Interface()))
1220
+}
1221
+
911 1222
 // IsEmail is the validation function for validating if the current field's value is a valid email address.
912 1223
 func isEmail(fl FieldLevel) bool {
913 1224
 	return emailRegex.MatchString(fl.Field().String())
@@ -945,12 +1256,22 @@ func isHexadecimal(fl FieldLevel) bool {
945 1256
 
946 1257
 // IsNumber is the validation function for validating if the current field's value is a valid number.
947 1258
 func isNumber(fl FieldLevel) bool {
948
-	return numberRegex.MatchString(fl.Field().String())
1259
+	switch fl.Field().Kind() {
1260
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64:
1261
+		return true
1262
+	default:
1263
+		return numberRegex.MatchString(fl.Field().String())
1264
+	}
949 1265
 }
950 1266
 
951 1267
 // IsNumeric is the validation function for validating if the current field's value is a valid numeric value.
952 1268
 func isNumeric(fl FieldLevel) bool {
953
-	return numericRegex.MatchString(fl.Field().String())
1269
+	switch fl.Field().Kind() {
1270
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64:
1271
+		return true
1272
+	default:
1273
+		return numericRegex.MatchString(fl.Field().String())
1274
+	}
954 1275
 }
955 1276
 
956 1277
 // IsAlphanum is the validation function for validating if the current field's value is a valid alphanumeric value.
@@ -980,22 +1301,101 @@ func isDefault(fl FieldLevel) bool {
980 1301
 
981 1302
 // HasValue is the validation function for validating if the current field's value is not the default static value.
982 1303
 func hasValue(fl FieldLevel) bool {
1304
+	return requireCheckFieldKind(fl, "")
1305
+}
983 1306
 
1307
+// requireCheckField is a func for check field kind
1308
+func requireCheckFieldKind(fl FieldLevel, param string) bool {
984 1309
 	field := fl.Field()
985
-
1310
+	if len(param) > 0 {
1311
+		field = fl.Parent().FieldByName(param)
1312
+	}
986 1313
 	switch field.Kind() {
987 1314
 	case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
988 1315
 		return !field.IsNil()
989 1316
 	default:
990
-
991 1317
 		if fl.(*validate).fldIsPointer && field.Interface() != nil {
992 1318
 			return true
993 1319
 		}
994
-
995 1320
 		return field.IsValid() && field.Interface() != reflect.Zero(field.Type()).Interface()
996 1321
 	}
997 1322
 }
998 1323
 
1324
+// RequiredWith is the validation function
1325
+// The field under validation must be present and not empty only if any of the other specified fields are present.
1326
+func requiredWith(fl FieldLevel) bool {
1327
+
1328
+	params := parseOneOfParam2(fl.Param())
1329
+	for _, param := range params {
1330
+
1331
+		if requireCheckFieldKind(fl, param) {
1332
+			return requireCheckFieldKind(fl, "")
1333
+		}
1334
+	}
1335
+
1336
+	return true
1337
+}
1338
+
1339
+// RequiredWithAll is the validation function
1340
+// The field under validation must be present and not empty only if all of the other specified fields are present.
1341
+func requiredWithAll(fl FieldLevel) bool {
1342
+
1343
+	isValidateCurrentField := true
1344
+	params := parseOneOfParam2(fl.Param())
1345
+	for _, param := range params {
1346
+
1347
+		if !requireCheckFieldKind(fl, param) {
1348
+			isValidateCurrentField = false
1349
+		}
1350
+	}
1351
+
1352
+	if isValidateCurrentField {
1353
+		return requireCheckFieldKind(fl, "")
1354
+	}
1355
+
1356
+	return true
1357
+}
1358
+
1359
+// RequiredWithout is the validation function
1360
+// The field under validation must be present and not empty only when any of the other specified fields are not present.
1361
+func requiredWithout(fl FieldLevel) bool {
1362
+
1363
+	isValidateCurrentField := false
1364
+	params := parseOneOfParam2(fl.Param())
1365
+	for _, param := range params {
1366
+
1367
+		if requireCheckFieldKind(fl, param) {
1368
+			isValidateCurrentField = true
1369
+		}
1370
+	}
1371
+
1372
+	if !isValidateCurrentField {
1373
+		return requireCheckFieldKind(fl, "")
1374
+	}
1375
+
1376
+	return true
1377
+}
1378
+
1379
+// RequiredWithoutAll is the validation function
1380
+// The field under validation must be present and not empty only when all of the other specified fields are not present.
1381
+func requiredWithoutAll(fl FieldLevel) bool {
1382
+
1383
+	isValidateCurrentField := true
1384
+	params := parseOneOfParam2(fl.Param())
1385
+	for _, param := range params {
1386
+
1387
+		if requireCheckFieldKind(fl, param) {
1388
+			isValidateCurrentField = false
1389
+		}
1390
+	}
1391
+
1392
+	if isValidateCurrentField {
1393
+		return requireCheckFieldKind(fl, "")
1394
+	}
1395
+
1396
+	return true
1397
+}
1398
+
999 1399
 // IsGteField is the validation function for validating if the current field's value is greater than or equal to the field specified by the param's value.
1000 1400
 func isGteField(fl FieldLevel) bool {
1001 1401
 
@@ -1577,3 +1977,19 @@ func isFQDN(fl FieldLevel) bool {
1577 1977
 	return strings.ContainsAny(val, ".") &&
1578 1978
 		hostnameRegexRFC952.MatchString(val)
1579 1979
 }
1980
+
1981
+// IsDir is the validation function for validating if the current field's value is a valid directory.
1982
+func isDir(fl FieldLevel) bool {
1983
+	field := fl.Field()
1984
+
1985
+	if field.Kind() == reflect.String {
1986
+		fileInfo, err := os.Stat(field.String())
1987
+		if err != nil {
1988
+			return false
1989
+		}
1990
+
1991
+		return fileInfo.IsDir()
1992
+	}
1993
+
1994
+	panic(fmt.Sprintf("Bad field type %T", field.Interface()))
1995
+}

+ 1
- 1
vendor/gopkg.in/go-playground/validator.v9/cache.go View File

@@ -223,7 +223,7 @@ func (v *Validate) parseFieldTagsRecursive(tag string, fieldName string, alias s
223 223
 			current.typeof = typeKeys
224 224
 
225 225
 			if i == 0 || prevTag != typeDive {
226
-				panic(fmt.Sprintf("'%s' tag must be immediately preceeded by the '%s' tag", keysTag, diveTag))
226
+				panic(fmt.Sprintf("'%s' tag must be immediately preceded by the '%s' tag", keysTag, diveTag))
227 227
 			}
228 228
 
229 229
 			current.typeof = typeKeys

+ 220
- 26
vendor/gopkg.in/go-playground/validator.v9/doc.go View File

@@ -31,7 +31,7 @@ Custom Validation Functions
31 31
 Custom Validation functions can be added. Example:
32 32
 
33 33
 	// Structure
34
-	func customFunc(fl FieldLevel) bool {
34
+	func customFunc(fl validator.FieldLevel) bool {
35 35
 
36 36
 		if fl.Field().String() == "invalid" {
37 37
 			return false
@@ -168,7 +168,7 @@ StructOnly
168 168
 
169 169
 When a field that is a nested struct is encountered, and contains this flag
170 170
 any validation on the nested struct will be run, but none of the nested
171
-struct fields will be validated. This is usefull if inside of you program
171
+struct fields will be validated. This is useful if inside of your program
172 172
 you know the struct will be valid, but need to verify it has been assigned.
173 173
 NOTE: only "required" and "omitempty" can be used on a struct itself.
174 174
 
@@ -245,6 +245,68 @@ ensures the value is not nil.
245 245
 
246 246
 	Usage: required
247 247
 
248
+Required With
249
+
250
+The field under validation must be present and not empty only if any
251
+of the other specified fields are present. For strings ensures value is
252
+not "". For slices, maps, pointers, interfaces, channels and functions
253
+ensures the value is not nil.
254
+
255
+	Usage: required_with
256
+
257
+Examples:
258
+
259
+	// require the field if the Field1 is present:
260
+	Usage: required_with=Field1
261
+
262
+	// require the field if the Field1 or Field2 is present:
263
+	Usage: required_with=Field1 Field2
264
+
265
+Required With All
266
+
267
+The field under validation must be present and not empty only if all
268
+of the other specified fields are present. For strings ensures value is
269
+not "". For slices, maps, pointers, interfaces, channels and functions
270
+ensures the value is not nil.
271
+
272
+	Usage: required_with_all
273
+
274
+Example:
275
+
276
+	// require the field if the Field1 and Field2 is present:
277
+	Usage: required_with_all=Field1 Field2
278
+
279
+Required Without
280
+
281
+The field under validation must be present and not empty only when any
282
+of the other specified fields are not present. For strings ensures value is
283
+not "". For slices, maps, pointers, interfaces, channels and functions
284
+ensures the value is not nil.
285
+
286
+	Usage: required_without
287
+
288
+Examples:
289
+
290
+	// require the field if the Field1 is not present:
291
+	Usage: required_without=Field1
292
+
293
+	// require the field if the Field1 or Field2 is not present:
294
+	Usage: required_without=Field1 Field2
295
+
296
+Required Without All
297
+
298
+The field under validation must be present and not empty only when all
299
+of the other specified fields are not present. For strings ensures value is
300
+not "". For slices, maps, pointers, interfaces, channels and functions
301
+ensures the value is not nil.
302
+
303
+	Usage: required_without_all
304
+
305
+Example:
306
+
307
+	// require the field if the Field1 and Field2 is not present:
308
+	Usage: required_without_all=Field1 Field2
309
+
248 310
 Is Default
249 311
 
250 312
 This validates that the value is the default value and is almost the
@@ -503,9 +565,26 @@ to the top level struct.
503 565
 
504 566
 	Usage: ltecsfield=InnerStructField.Field
505 567
 
568
+Field Contains Another Field
569
+
570
+This does the same as contains except for struct fields. It should only be used
571
+with string types. See the behavior of reflect.Value.String() for behavior on
572
+other types.
573
+
574
+	Usage: containsfield=InnerStructField.Field
575
+
576
+Field Excludes Another Field
577
+
578
+This does the same as excludes except for struct fields. It should only be used
579
+with string types. See the behavior of reflect.Value.String() for behavior on
580
+other types.
581
+
582
+	Usage: excludesfield=InnerStructField.Field
583
+
506 584
 Unique
507 585
 
508 586
 For arrays & slices, unique will ensure that there are no duplicates.
587
+For maps, unique will ensure that there are no duplicate values.
509 588
 
510 589
 	Usage: unique
511 590
 
@@ -537,6 +616,7 @@ Numeric
537 616
 
538 617
 This validates that a string value contains a basic numeric value.
539 618
 basic excludes exponents etc...
619
+for integers or float it returns true.
540 620
 
541 621
 	Usage: numeric
542 622
 
@@ -581,10 +661,18 @@ E-mail String
581 661
 
582 662
 This validates that a string value contains a valid email
583 663
 This may not conform to all possibilities of any rfc standard, but neither
584
-does any email provider accept all posibilities.
664
+does any email provider accept all possibilities.
585 665
 
586 666
 	Usage: email
587 667
 
668
+File path
669
+
670
+This validates that a string value contains a valid file path and that
671
+the file exists on the machine.
672
+This is done using os.Stat, which is a platform independent function.
673
+
674
+	Usage: file
675
+
588 676
 URL String
589 677
 
590 678
 This validates that a string value contains a valid url
@@ -600,6 +688,13 @@ This will accept any uri the golang request uri accepts
600 688
 
601 689
 	Usage: uri
602 690
 
691
+Urn RFC 2141 String
692
+
693
+This validataes that a string value contains a valid URN
694
+according to the RFC 2141 spec.
695
+
696
+	Usage: urn_rfc2141
697
+
603 698
 Base64 String
604 699
 
605 700
 This validates that a string value contains a valid base64 value.
@@ -609,6 +704,40 @@ this with the omitempty tag.
609 704
 
610 705
 	Usage: base64
611 706
 
707
+Base64URL String
708
+
709
+This validates that a string value contains a valid base64 URL safe value
710
+according the the RFC4648 spec.
711
+Although an empty string is a valid base64 URL safe value, this will report
712
+an empty string as an error, if you wish to accept an empty string as valid
713
+you can use this with the omitempty tag.
714
+
715
+	Usage: base64url
716
+
717
+Bitcoin Address
718
+
719
+This validates that a string value contains a valid bitcoin address.
720
+The format of the string is checked to ensure it matches one of the three formats
721
+P2PKH, P2SH and performs checksum validation.
722
+
723
+	Usage: btc_addr
724
+
725
+Bitcoin Bech32 Address (segwit)
726
+
727
+This validates that a string value contains a valid bitcoin Bech32 address as defined
728
+by bip-0173 (https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki)
729
+Special thanks to Pieter Wuille for providng reference implementations.
730
+
731
+	Usage: btc_addr_bech32
732
+
733
+Ethereum Address
734
+
735
+This validates that a string value contains a valid ethereum address.
736
+The format of the string is checked to ensure it matches the standard Ethereum address format
737
+Full validation is blocked by https://github.com/golang/crypto/pull/28
738
+
739
+	Usage: eth_addr
740
+
612 741
 Contains
613 742
 
614 743
 This validates that a string value contains the substring value.
@@ -647,6 +776,18 @@ This validates that a string value does not contain the supplied rune value.
647 776
 
648 777
 	Usage: excludesrune=@
649 778
 
779
+Starts With
780
+
781
+This validates that a string value starts with the supplied string value
782
+
783
+	Usage: startswith=hello
784
+
785
+Ends With
786
+
787
+This validates that a string value ends with the supplied string value
788
+
789
+	Usage: endswith=goodbye
790
+
650 791
 International Standard Book Number
651 792
 
652 793
 This validates that a string value contains a valid isbn10 or isbn13 value.
@@ -665,28 +806,27 @@ This validates that a string value contains a valid isbn13 value.
665 806
 
666 807
 	Usage: isbn13
667 808
 
668
-
669 809
 Universally Unique Identifier UUID
670 810
 
671
-This validates that a string value contains a valid UUID.
811
+This validates that a string value contains a valid UUID. Uppercase UUID values will not pass - use `uuid_rfc4122` instead.
672 812
 
673 813
 	Usage: uuid
674 814
 
675 815
 Universally Unique Identifier UUID v3
676 816
 
677
-This validates that a string value contains a valid version 3 UUID.
817
+This validates that a string value contains a valid version 3 UUID.  Uppercase UUID values will not pass - use `uuid3_rfc4122` instead.
678 818
 
679 819
 	Usage: uuid3
680 820
 
681 821
 Universally Unique Identifier UUID v4
682 822
 
683
-This validates that a string value contains a valid version 4 UUID.
823
+This validates that a string value contains a valid version 4 UUID.  Uppercase UUID values will not pass - use `uuid4_rfc4122` instead.
684 824
 
685 825
 	Usage: uuid4
686 826
 
687 827
 Universally Unique Identifier UUID v5
688 828
 
689
-This validates that a string value contains a valid version 5 UUID.
829
+This validates that a string value contains a valid version 5 UUID.  Uppercase UUID values will not pass - use `uuid5_rfc4122` instead.
690 830
 
691 831
 	Usage: uuid5
692 832
 
@@ -738,103 +878,103 @@ This validates that a string value contains a valid U.S. Social Security Number.
738 878
 
739 879
 Internet Protocol Address IP
740 880
 
741
-This validates that a string value contains a valid IP Adress.
881
+This validates that a string value contains a valid IP Address.
742 882
 
743 883
 	Usage: ip
744 884
 
745 885
 Internet Protocol Address IPv4
746 886
 
747
-This validates that a string value contains a valid v4 IP Adress.
887
+This validates that a string value contains a valid v4 IP Address.
748 888
 
749 889
 	Usage: ipv4
750 890
 
751 891
 Internet Protocol Address IPv6
752 892
 
753
-This validates that a string value contains a valid v6 IP Adress.
893
+This validates that a string value contains a valid v6 IP Address.
754 894
 
755 895
 	Usage: ipv6
756 896
 
757 897
 Classless Inter-Domain Routing CIDR
758 898
 
759
-This validates that a string value contains a valid CIDR Adress.
899
+This validates that a string value contains a valid CIDR Address.
760 900
 
761 901
 	Usage: cidr
762 902
 
763 903
 Classless Inter-Domain Routing CIDRv4
764 904
 
765
-This validates that a string value contains a valid v4 CIDR Adress.
905
+This validates that a string value contains a valid v4 CIDR Address.
766 906
 
767 907
 	Usage: cidrv4
768 908
 
769 909
 Classless Inter-Domain Routing CIDRv6
770 910
 
771
-This validates that a string value contains a valid v6 CIDR Adress.
911
+This validates that a string value contains a valid v6 CIDR Address.
772 912
 
773 913
 	Usage: cidrv6
774 914
 
775 915
 Transmission Control Protocol Address TCP
776 916
 
777
-This validates that a string value contains a valid resolvable TCP Adress.
917
+This validates that a string value contains a valid resolvable TCP Address.
778 918
 
779 919
 	Usage: tcp_addr
780 920
 
781 921
 Transmission Control Protocol Address TCPv4
782 922
 
783
-This validates that a string value contains a valid resolvable v4 TCP Adress.
923
+This validates that a string value contains a valid resolvable v4 TCP Address.
784 924
 
785 925
 	Usage: tcp4_addr
786 926
 
787 927
 Transmission Control Protocol Address TCPv6
788 928
 
789
-This validates that a string value contains a valid resolvable v6 TCP Adress.
929
+This validates that a string value contains a valid resolvable v6 TCP Address.
790 930
 
791 931
 	Usage: tcp6_addr
792 932
 
793 933
 User Datagram Protocol Address UDP
794 934
 
795
-This validates that a string value contains a valid resolvable UDP Adress.
935
+This validates that a string value contains a valid resolvable UDP Address.
796 936
 
797 937
 	Usage: udp_addr
798 938
 
799 939
 User Datagram Protocol Address UDPv4
800 940
 
801
-This validates that a string value contains a valid resolvable v4 UDP Adress.
941
+This validates that a string value contains a valid resolvable v4 UDP Address.
802 942
 
803 943
 	Usage: udp4_addr
804 944
 
805 945
 User Datagram Protocol Address UDPv6
806 946
 
807
-This validates that a string value contains a valid resolvable v6 UDP Adress.
947
+This validates that a string value contains a valid resolvable v6 UDP Address.
808 948
 
809 949
 	Usage: udp6_addr
810 950
 
811 951
 Internet Protocol Address IP
812 952
 
813
-This validates that a string value contains a valid resolvable IP Adress.
953
+This validates that a string value contains a valid resolvable IP Address.
814 954
 
815 955
 	Usage: ip_addr
816 956
 
817 957
 Internet Protocol Address IPv4
818 958
 
819
-This validates that a string value contains a valid resolvable v4 IP Adress.
959
+This validates that a string value contains a valid resolvable v4 IP Address.
820 960
 
821 961
 	Usage: ip4_addr
822 962
 
823 963
 Internet Protocol Address IPv6
824 964
 
825
-This validates that a string value contains a valid resolvable v6 IP Adress.
965
+This validates that a string value contains a valid resolvable v6 IP Address.
826 966
 
827 967
 	Usage: ip6_addr
828 968
 
829 969
 Unix domain socket end point Address
830 970
 
831
-This validates that a string value contains a valid Unix Adress.
971
+This validates that a string value contains a valid Unix Address.
832 972
 
833 973
 	Usage: unix_addr
834 974
 
835 975
 Media Access Control Address MAC
836 976
 
837
-This validates that a string value contains a valid MAC Adress.
977
+This validates that a string value contains a valid MAC Address.
838 978
 
839 979
 	Usage: mac
840 980
 
@@ -860,6 +1000,35 @@ This validates that a string value contains a valid FQDN.
860 1000
 
861 1001
 	Usage: fqdn
862 1002
 
1003
+HTML Tags
1004
+
1005
+This validates that a string value appears to be an HTML element tag
1006
+including those described at https://developer.mozilla.org/en-US/docs/Web/HTML/Element
1007
+
1008
+	Usage: html
1009
+
1010
+HTML Encoded
1011
+
1012
+This validates that a string value is a proper character reference in decimal
1013
+or hexadecimal format
1014
+
1015
+	Usage: html_encoded
1016
+
1017
+URL Encoded
1018
+
1019
+This validates that a string value is percent-encoded (URL encoded) according
1020
+to https://tools.ietf.org/html/rfc3986#section-2.1
1021
+
1022
+	Usage: url_encoded
1023
+
1024
+Directory
1025
+
1026
+This validates that a string value contains a valid directory and that
1027
+it exists on the machine.
1028
+This is done using os.Stat, which is a platform independent function.
1029
+
1030
+	Usage: dir
1031
+
863 1032
 Alias Validators and Tags
864 1033
 
865 1034
 NOTE: When returning an error, the tag returned in "FieldError" will be
@@ -879,7 +1048,7 @@ Validator notes:
879 1048
 		of a regex which conflict with the validation definitions. Although
880 1049
 		workarounds can be made, they take away from using pure regex's.
881 1050
 		Furthermore it's quick and dirty but the regex's become harder to
882
-		maintain and are not reusable, so it's as much a programming philosiphy
1051
+		maintain and are not reusable, so it's as much a programming philosophy
883 1052
 		as anything.
884 1053
 
885 1054
 		In place of this new validator functions should be created; a regex can
@@ -903,5 +1072,30 @@ that should not make it to production.
903 1072
 	}
904 1073
 
905 1074
 	validate.Struct(t) // this will panic
1075
+
1076
+Non standard validators
1077
+
1078
+A collection of validation rules that are frequently needed but are more
1079
+complex than the ones found in the baked in validators.
1080
+A non standard validator must be registered manually using any tag you like.
1081
+See below examples of registration and use.
1082
+
1083
+	type Test struct {
1084
+		TestField string `validate:"yourtag"`
1085
+	}
1086
+
1087
+	t := &Test{
1088
+		TestField: "Test"
1089
+	}
1090
+
1091
+	validate := validator.New()
1092
+	validate.RegisterValidation("yourtag", validations.ValidatorName)
1093
+
1094
+	NotBlank
1095
+		This validates that the value is not blank or with length zero.
1096
+		For strings ensures they do not contain only spaces. For channels, maps, slices and arrays
1097
+		ensures they don't have zero length. For others, a non empty value is required.
1098
+
1099
+		Usage: notblank
906 1100
 */
907 1101
 package validator

+ 1
- 1
vendor/gopkg.in/go-playground/validator.v9/errors.go View File

@@ -122,7 +122,7 @@ type FieldError interface {
122 122
 	// fields actual name.
123 123
 	//
124 124
 	// eq. JSON name "fname"
125
-	// see ActualField for comparison
125
+	// see StructField for comparison
126 126
 	Field() string
127 127
 
128 128
 	// returns the fields actual name from the struct, when able to determine.

+ 1
- 1
vendor/gopkg.in/go-playground/validator.v9/field_level.go View File

@@ -17,7 +17,7 @@ type FieldLevel interface {
17 17
 	Field() reflect.Value
18 18
 
19 19
 	// returns the field's name with the tag
20
-	// name takeing precedence over the fields actual name.
20
+	// name taking precedence over the fields actual name.
21 21
 	FieldName() string
22 22
 
23 23
 	// returns the struct field's name

+ 86
- 58
vendor/gopkg.in/go-playground/validator.v9/regexes.go View File

@@ -3,65 +3,93 @@ package validator
3 3
 import "regexp"
4 4
 
5 5
 const (
6
-	alphaRegexString               = "^[a-zA-Z]+$"
7
-	alphaNumericRegexString        = "^[a-zA-Z0-9]+$"
8
-	alphaUnicodeRegexString        = "^[\\p{L}]+$"
9
-	alphaUnicodeNumericRegexString = "^[\\p{L}\\p{N}]+$"
10
-	numericRegexString             = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
11
-	numberRegexString              = "^[0-9]+$"
12
-	hexadecimalRegexString         = "^[0-9a-fA-F]+$"
13
-	hexcolorRegexString            = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
14
-	rgbRegexString                 = "^rgb\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*\\)$"
15
-	rgbaRegexString                = "^rgba\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
16
-	hslRegexString                 = "^hsl\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*\\)$"
17
-	hslaRegexString                = "^hsla\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
18
-	emailRegexString               = "^(?:(?:(?:(?:[a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(?:\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|(?:(?:\\x22)(?:(?:(?:(?:\\x20|\\x09)*(?:\\x0d\\x0a))?(?:\\x20|\\x09)+)?(?:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(?:\\(?:[\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(?:(?:(?:\\x20|\\x09)*(?:\\x0d\\x0a))?(\\x20|\\x09)+)?(?:\\x22)))@(?:(?:(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(?:(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])(?:[a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(?:(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(?:(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])(?:[a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$"
19
-	base64RegexString              = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
20
-	iSBN10RegexString              = "^(?:[0-9]{9}X|[0-9]{10})$"
21
-	iSBN13RegexString              = "^(?:(?:97(?:8|9))[0-9]{10})$"
22
-	uUID3RegexString               = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$"
23
-	uUID4RegexString               = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
24
-	uUID5RegexString               = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
25
-	uUIDRegexString                = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
26
-	aSCIIRegexString               = "^[\x00-\x7F]*$"
27
-	printableASCIIRegexString      = "^[\x20-\x7E]*$"
28
-	multibyteRegexString           = "[^\x00-\x7F]"
29
-	dataURIRegexString             = "^data:.+\\/(.+);base64$"
30
-	latitudeRegexString            = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$"
31
-	longitudeRegexString           = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$"
32
-	sSNRegexString                 = `^\d{3}[- ]?\d{2}[- ]?\d{4}$`
33
-	hostnameRegexStringRFC952      = `^[a-zA-Z][a-zA-Z0-9\-\.]+[a-z-Az0-9]$`    // https://tools.ietf.org/html/rfc952
34
-	hostnameRegexStringRFC1123     = `^[a-zA-Z0-9][a-zA-Z0-9\-\.]+[a-z-Az0-9]$` // accepts hostname starting with a digit https://tools.ietf.org/html/rfc1123
6
+	alphaRegexString                 = "^[a-zA-Z]+$"
7
+	alphaNumericRegexString          = "^[a-zA-Z0-9]+$"
8
+	alphaUnicodeRegexString          = "^[\\p{L}]+$"
9
+	alphaUnicodeNumericRegexString   = "^[\\p{L}\\p{N}]+$"
10
+	numericRegexString               = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
11
+	numberRegexString                = "^[0-9]+$"
12
+	hexadecimalRegexString           = "^[0-9a-fA-F]+$"
13
+	hexcolorRegexString              = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
14
+	rgbRegexString                   = "^rgb\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*\\)$"
15
+	rgbaRegexString                  = "^rgba\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
16
+	hslRegexString                   = "^hsl\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*\\)$"
17
+	hslaRegexString                  = "^hsla\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
18
+	emailRegexString                 = "^(?:(?:(?:(?:[a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(?:\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|(?:(?:\\x22)(?:(?:(?:(?:\\x20|\\x09)*(?:\\x0d\\x0a))?(?:\\x20|\\x09)+)?(?:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(?:(?:[\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(?:(?:(?:\\x20|\\x09)*(?:\\x0d\\x0a))?(\\x20|\\x09)+)?(?:\\x22))))@(?:(?:(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(?:(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])(?:[a-zA-Z]|\\d|-|\\.|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(?:(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(?:(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])(?:[a-zA-Z]|\\d|-|\\.|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$"
19
+	base64RegexString                = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
20
+	base64URLRegexString             = "^(?:[A-Za-z0-9-_]{4})*(?:[A-Za-z0-9-_]{2}==|[A-Za-z0-9-_]{3}=|[A-Za-z0-9-_]{4})$"
21
+	iSBN10RegexString                = "^(?:[0-9]{9}X|[0-9]{10})$"
22
+	iSBN13RegexString                = "^(?:(?:97(?:8|9))[0-9]{10})$"
23
+	uUID3RegexString                 = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$"
24
+	uUID4RegexString                 = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
25
+	uUID5RegexString                 = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
26
+	uUIDRegexString                  = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
27
+	uUID3RFC4122RegexString          = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-3[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
28
+	uUID4RFC4122RegexString          = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"
29
+	uUID5RFC4122RegexString          = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-5[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"
30
+	uUIDRFC4122RegexString           = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
31
+	aSCIIRegexString                 = "^[\x00-\x7F]*$"
32
+	printableASCIIRegexString        = "^[\x20-\x7E]*$"
33
+	multibyteRegexString             = "[^\x00-\x7F]"
34
+	dataURIRegexString               = "^data:.+\\/(.+);base64$"
35
+	latitudeRegexString              = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$"
36
+	longitudeRegexString             = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$"
37
+	sSNRegexString                   = `^[0-9]{3}[ -]?(0[1-9]|[1-9][0-9])[ -]?([1-9][0-9]{3}|[0-9][1-9][0-9]{2}|[0-9]{2}[1-9][0-9]|[0-9]{3}[1-9])$`
38
+	hostnameRegexStringRFC952        = `^[a-zA-Z][a-zA-Z0-9\-\.]+[a-zA-Z0-9]$`    // https://tools.ietf.org/html/rfc952
39
+	hostnameRegexStringRFC1123       = `^[a-zA-Z0-9][a-zA-Z0-9\-\.]+[a-zA-Z0-9]$` // accepts hostname starting with a digit https://tools.ietf.org/html/rfc1123
40
+	btcAddressRegexString            = `^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$`        // bitcoin address
41
+	btcAddressUpperRegexStringBech32 = `^BC1[02-9AC-HJ-NP-Z]{7,76}$`              // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32
42
+	btcAddressLowerRegexStringBech32 = `^bc1[02-9ac-hj-np-z]{7,76}$`              // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32
43
+	ethAddressRegexString            = `^0x[0-9a-fA-F]{40}$`
44
+	ethAddressUpperRegexString       = `^0x[0-9A-F]{40}$`
45
+	ethAddressLowerRegexString       = `^0x[0-9a-f]{40}$`
46
+	uRLEncodedRegexString            = `(%[A-Fa-f0-9]{2})`
47
+	hTMLEncodedRegexString           = `&#[x]?([0-9a-fA-F]{2})|(&gt)|(&lt)|(&quot)|(&amp)+[;]?`
48
+	hTMLRegexString                  = `<[/]?([a-zA-Z]+).*?>`
35 49
 )
36 50
 
37 51
 var (
38
-	alphaRegex               = regexp.MustCompile(alphaRegexString)
39
-	alphaNumericRegex        = regexp.MustCompile(alphaNumericRegexString)
40
-	alphaUnicodeRegex        = regexp.MustCompile(alphaUnicodeRegexString)
41
-	alphaUnicodeNumericRegex = regexp.MustCompile(alphaUnicodeNumericRegexString)
42
-	numericRegex             = regexp.MustCompile(numericRegexString)
43
-	numberRegex              = regexp.MustCompile(numberRegexString)
44
-	hexadecimalRegex         = regexp.MustCompile(hexadecimalRegexString)
45
-	hexcolorRegex            = regexp.MustCompile(hexcolorRegexString)
46
-	rgbRegex                 = regexp.MustCompile(rgbRegexString)
47
-	rgbaRegex                = regexp.MustCompile(rgbaRegexString)
48
-	hslRegex                 = regexp.MustCompile(hslRegexString)
49
-	hslaRegex                = regexp.MustCompile(hslaRegexString)
50
-	emailRegex               = regexp.MustCompile(emailRegexString)
51
-	base64Regex              = regexp.MustCompile(base64RegexString)
52
-	iSBN10Regex              = regexp.MustCompile(iSBN10RegexString)
53
-	iSBN13Regex              = regexp.MustCompile(iSBN13RegexString)
54
-	uUID3Regex               = regexp.MustCompile(uUID3RegexString)
55
-	uUID4Regex               = regexp.MustCompile(uUID4RegexString)
56
-	uUID5Regex               = regexp.MustCompile(uUID5RegexString)
57
-	uUIDRegex                = regexp.MustCompile(uUIDRegexString)
58
-	aSCIIRegex               = regexp.MustCompile(aSCIIRegexString)
59
-	printableASCIIRegex      = regexp.MustCompile(printableASCIIRegexString)
60
-	multibyteRegex           = regexp.MustCompile(multibyteRegexString)
61
-	dataURIRegex             = regexp.MustCompile(dataURIRegexString)
62
-	latitudeRegex            = regexp.MustCompile(latitudeRegexString)
63
-	longitudeRegex           = regexp.MustCompile(longitudeRegexString)
64
-	sSNRegex                 = regexp.MustCompile(sSNRegexString)
65
-	hostnameRegexRFC952      = regexp.MustCompile(hostnameRegexStringRFC952)
66
-	hostnameRegexRFC1123     = regexp.MustCompile(hostnameRegexStringRFC1123)
52
+	alphaRegex                 = regexp.MustCompile(alphaRegexString)
53
+	alphaNumericRegex          = regexp.MustCompile(alphaNumericRegexString)
54
+	alphaUnicodeRegex          = regexp.MustCompile(alphaUnicodeRegexString)
55
+	alphaUnicodeNumericRegex   = regexp.MustCompile(alphaUnicodeNumericRegexString)
56
+	numericRegex               = regexp.MustCompile(numericRegexString)
57
+	numberRegex                = regexp.MustCompile(numberRegexString)
58
+	hexadecimalRegex           = regexp.MustCompile(hexadecimalRegexString)
59
+	hexcolorRegex              = regexp.MustCompile(hexcolorRegexString)
60
+	rgbRegex                   = regexp.MustCompile(rgbRegexString)
61
+	rgbaRegex                  = regexp.MustCompile(rgbaRegexString)
62
+	hslRegex                   = regexp.MustCompile(hslRegexString)
63
+	hslaRegex                  = regexp.MustCompile(hslaRegexString)
64
+	emailRegex                 = regexp.MustCompile(emailRegexString)
65
+	base64Regex                = regexp.MustCompile(base64RegexString)
66
+	base64URLRegex             = regexp.MustCompile(base64URLRegexString)
67
+	iSBN10Regex                = regexp.MustCompile(iSBN10RegexString)
68
+	iSBN13Regex                = regexp.MustCompile(iSBN13RegexString)
69
+	uUID3Regex                 = regexp.MustCompile(uUID3RegexString)
70
+	uUID4Regex                 = regexp.MustCompile(uUID4RegexString)
71
+	uUID5Regex                 = regexp.MustCompile(uUID5RegexString)
72
+	uUIDRegex                  = regexp.MustCompile(uUIDRegexString)
73
+	uUID3RFC4122Regex          = regexp.MustCompile(uUID3RFC4122RegexString)
74
+	uUID4RFC4122Regex          = regexp.MustCompile(uUID4RFC4122RegexString)
75
+	uUID5RFC4122Regex          = regexp.MustCompile(uUID5RFC4122RegexString)
76
+	uUIDRFC4122Regex           = regexp.MustCompile(uUIDRFC4122RegexString)
77
+	aSCIIRegex                 = regexp.MustCompile(aSCIIRegexString)
78
+	printableASCIIRegex        = regexp.MustCompile(printableASCIIRegexString)
79
+	multibyteRegex             = regexp.MustCompile(multibyteRegexString)
80
+	dataURIRegex               = regexp.MustCompile(dataURIRegexString)
81
+	latitudeRegex              = regexp.MustCompile(latitudeRegexString)
82
+	longitudeRegex             = regexp.MustCompile(longitudeRegexString)
83
+	sSNRegex                   = regexp.MustCompile(sSNRegexString)
84
+	hostnameRegexRFC952        = regexp.MustCompile(hostnameRegexStringRFC952)
85
+	hostnameRegexRFC1123       = regexp.MustCompile(hostnameRegexStringRFC1123)
86
+	btcAddressRegex            = regexp.MustCompile(btcAddressRegexString)
87
+	btcUpperAddressRegexBech32 = regexp.MustCompile(btcAddressUpperRegexStringBech32)
88
+	btcLowerAddressRegexBech32 = regexp.MustCompile(btcAddressLowerRegexStringBech32)
89
+	ethAddressRegex            = regexp.MustCompile(ethAddressRegexString)
90
+	ethaddressRegexUpper       = regexp.MustCompile(ethAddressUpperRegexString)
91
+	ethAddressRegexLower       = regexp.MustCompile(ethAddressLowerRegexString)
92
+	uRLEncodedRegex            = regexp.MustCompile(uRLEncodedRegexString)
93
+	hTMLEncodedRegex           = regexp.MustCompile(hTMLEncodedRegexString)
94
+	hTMLRegex                  = regexp.MustCompile(hTMLRegexString)
67 95
 )

+ 7
- 7
vendor/gopkg.in/go-playground/validator.v9/struct_level.go View File

@@ -9,10 +9,10 @@ import (
9 9
 type StructLevelFunc func(sl StructLevel)
10 10
 
11 11
 // StructLevelFuncCtx accepts all values needed for struct level validation
12
-// but also allows passing of contextual validation information vi context.Context.
12
+// but also allows passing of contextual validation information via context.Context.
13 13
 type StructLevelFuncCtx func(ctx context.Context, sl StructLevel)
14 14
 
15
-// wrapStructLevelFunc wraps noramal StructLevelFunc makes it compatible with StructLevelFuncCtx
15
+// wrapStructLevelFunc wraps normal StructLevelFunc makes it compatible with StructLevelFuncCtx
16 16
 func wrapStructLevelFunc(fn StructLevelFunc) StructLevelFuncCtx {
17 17
 	return func(ctx context.Context, sl StructLevel) {
18 18
 		fn(sl)
@@ -23,8 +23,8 @@ func wrapStructLevelFunc(fn StructLevelFunc) StructLevelFuncCtx {
23 23
 // to validate a struct
24 24
 type StructLevel interface {
25 25
 
26
-	// returns the main validation object, in case one want to call validations internally.
27
-	// this is so you don;t have to use anonymous functoins to get access to the validate
26
+	// returns the main validation object, in case one wants to call validations internally.
27
+	// this is so you don't have to use anonymous functions to get access to the validate
28 28
 	// instance.
29 29
 	Validator() *Validate
30 30
 
@@ -39,7 +39,7 @@ type StructLevel interface {
39 39
 
40 40
 	// ExtractType gets the actual underlying type of field value.
41 41
 	// It will dive into pointers, customTypes and return you the
42
-	// underlying value and it's kind.
42
+	// underlying value and its kind.
43 43
 	ExtractType(field reflect.Value) (value reflect.Value, kind reflect.Kind, nullable bool)
44 44
 
45 45
 	// reports an error just by passing the field and tag information
@@ -47,7 +47,7 @@ type StructLevel interface {
47 47
 	// NOTES:
48 48
 	//
49 49
 	// fieldName and altName get appended to the existing namespace that
50
-	// validator is on. eg. pass 'FirstName' or 'Names[0]' depending
50
+	// validator is on. e.g. pass 'FirstName' or 'Names[0]' depending
51 51
 	// on the nesting
52 52
 	//
53 53
 	// tag can be an existing validation tag or just something you make up
@@ -60,7 +60,7 @@ type StructLevel interface {
60 60
 	//
61 61
 	// relativeNamespace and relativeActualNamespace get appended to the
62 62
 	// existing namespace that validator is on.
63
-	// eg. pass 'User.FirstName' or 'Users[0].FirstName' depending
63
+	// e.g. pass 'User.FirstName' or 'Users[0].FirstName' depending
64 64
 	// on the nesting. most of the time they will be blank, unless you validate
65 65
 	// at a level lower the the current field depth
66 66
 	ReportValidationErrors(relativeNamespace, relativeActualNamespace string, errs ValidationErrors)

+ 1
- 1
vendor/gopkg.in/go-playground/validator.v9/translations.go View File

@@ -7,5 +7,5 @@ import ut "github.com/go-playground/universal-translator"
7 7
 type TranslationFunc func(ut ut.Translator, fe FieldError) string
8 8
 
9 9
 // RegisterTranslationsFunc allows for registering of translations
10
-// for a 'ut.Translator' for use withing the 'TranslationFunc'
10
+// for a 'ut.Translator' for use within the 'TranslationFunc'
11 11
 type RegisterTranslationsFunc func(ut ut.Translator) error

+ 2
- 2
vendor/gopkg.in/go-playground/validator.v9/validator.go View File

@@ -213,8 +213,8 @@ func (v *validate) traverseField(ctx context.Context, parent reflect.Value, curr
213 213
 		CONTINUE:
214 214
 			// if len == 0 then validating using 'Var' or 'VarWithValue'
215 215
 			// Var - doesn't make much sense to do it that way, should call 'Struct', but no harm...
216
-			// VarWithField - this allows for validating against each field withing the struct against a specific value
217
-			//                pretty handly in certain situations
216
+			// VarWithField - this allows for validating against each field within the struct against a specific value
217
+			//                pretty handy in certain situations
218 218
 			if len(cf.name) > 0 {
219 219
 				ns = append(append(ns, cf.altName...), '.')
220 220
 				structNs = append(append(structNs, cf.name...), '.')

+ 23
- 9
vendor/gopkg.in/go-playground/validator.v9/validator_instance.go View File

@@ -71,7 +71,7 @@ type Validate struct {
71 71
 	structCache      *structCache
72 72
 }
73 73
 
74
-// New returns a new instacne of 'validate' with sane defaults.
74
+// New returns a new instance of 'validate' with sane defaults.
75 75
 func New() *Validate {
76 76
 
77 77
 	tc := new(tagCache)
@@ -97,7 +97,7 @@ func New() *Validate {
97 97
 	for k, val := range bakedInValidators {
98 98
 
99 99
 		// no need to error check here, baked in will always be valid
100
-		v.registerValidation(k, wrapFunc(val), true)
100
+		_ = v.registerValidation(k, wrapFunc(val), true)
101 101
 	}
102 102
 
103 103
 	v.pool = &sync.Pool{
@@ -119,8 +119,17 @@ func (v *Validate) SetTagName(name string) {
119 119
 	v.tagName = name
120 120
 }
121 121
 
122
-// RegisterTagNameFunc registers a function to get another name from the
123
-// StructField eg. the JSON name
122
+// RegisterTagNameFunc registers a function to get alternate names for StructFields.
123
+//
124
+// eg. to use the names which have been specified for JSON representations of structs, rather than normal Go field names:
125
+//
126
+//    validate.RegisterTagNameFunc(func(fld reflect.StructField) string {
127
+//        name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
128
+//        if name == "-" {
129
+//            return ""
130
+//        }
131
+//        return name
132
+//    })
124 133
 func (v *Validate) RegisterTagNameFunc(fn TagNameFunc) {
125 134
 	v.tagNameFunc = fn
126 135
 	v.hasTagNameFunc = true
@@ -198,6 +207,11 @@ func (v *Validate) RegisterStructValidationCtx(fn StructLevelFuncCtx, types ...i
198 207
 	}
199 208
 
200 209
 	for _, t := range types {
210
+		tv := reflect.ValueOf(t)
211
+		if tv.Kind() == reflect.Ptr {
212
+			t = reflect.Indirect(tv).Interface()
213
+		}
214
+
201 215
 		v.structLevelFuncs[reflect.TypeOf(t)] = fn
202 216
 	}
203 217
 }
@@ -318,7 +332,7 @@ func (v *Validate) StructFilteredCtx(ctx context.Context, s interface{}, fn Filt
318 332
 	vd.ffn = fn
319 333
 	// vd.hasExcludes = false // only need to reset in StructPartial and StructExcept
320 334
 
321
-	vd.validateStruct(context.Background(), top, val, val.Type(), vd.ns[0:0], vd.actualNs[0:0], nil)
335
+	vd.validateStruct(ctx, top, val, val.Type(), vd.ns[0:0], vd.actualNs[0:0], nil)
322 336
 
323 337
 	if len(vd.errs) > 0 {
324 338
 		err = vd.errs
@@ -489,7 +503,7 @@ func (v *Validate) StructExceptCtx(ctx context.Context, s interface{}, fields ..
489 503
 //
490 504
 // WARNING: a struct can be passed for validation eg. time.Time is a struct or
491 505
 // if you have a custom type and have registered a custom type handler, so must
492
-// allow it; however unforseen validations will occur if trying to validate a
506
+// allow it; however unforeseen validations will occur if trying to validate a
493 507
 // struct that is meant to be passed to 'validate.Struct'
494 508
 //
495 509
 // It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
@@ -507,7 +521,7 @@ func (v *Validate) Var(field interface{}, tag string) error {
507 521
 //
508 522
 // WARNING: a struct can be passed for validation eg. time.Time is a struct or
509 523
 // if you have a custom type and have registered a custom type handler, so must
510
-// allow it; however unforseen validations will occur if trying to validate a
524
+// allow it; however unforeseen validations will occur if trying to validate a
511 525
 // struct that is meant to be passed to 'validate.Struct'
512 526
 //
513 527
 // It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
@@ -541,7 +555,7 @@ func (v *Validate) VarCtx(ctx context.Context, field interface{}, tag string) (e
541 555
 //
542 556
 // WARNING: a struct can be passed for validation eg. time.Time is a struct or
543 557
 // if you have a custom type and have registered a custom type handler, so must
544
-// allow it; however unforseen validations will occur if trying to validate a
558
+// allow it; however unforeseen validations will occur if trying to validate a
545 559
 // struct that is meant to be passed to 'validate.Struct'
546 560
 //
547 561
 // It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
@@ -560,7 +574,7 @@ func (v *Validate) VarWithValue(field interface{}, other interface{}, tag string
560 574
 //
561 575
 // WARNING: a struct can be passed for validation eg. time.Time is a struct or
562 576
 // if you have a custom type and have registered a custom type handler, so must
563
-// allow it; however unforseen validations will occur if trying to validate a
577
+// allow it; however unforeseen validations will occur if trying to validate a
564 578
 // struct that is meant to be passed to 'validate.Struct'
565 579
 //
566 580
 // It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.

Loading…
Cancel
Save