Update dependencies (#5518)
This commit is contained in:
33
vendor/github.com/asaskevich/govalidator/README.md
generated
vendored
33
vendor/github.com/asaskevich/govalidator/README.md
generated
vendored
@@ -83,14 +83,14 @@ This was changed to prevent data races when accessing custom validators.
|
||||
import "github.com/asaskevich/govalidator"
|
||||
|
||||
// before
|
||||
govalidator.CustomTypeTagMap["customByteArrayValidator"] = CustomTypeValidator(func(i interface{}, o interface{}) bool {
|
||||
govalidator.CustomTypeTagMap["customByteArrayValidator"] = func(i interface{}, o interface{}) bool {
|
||||
// ...
|
||||
})
|
||||
}
|
||||
|
||||
// after
|
||||
govalidator.CustomTypeTagMap.Set("customByteArrayValidator", CustomTypeValidator(func(i interface{}, o interface{}) bool {
|
||||
govalidator.CustomTypeTagMap.Set("customByteArrayValidator", func(i interface{}, o interface{}) bool {
|
||||
// ...
|
||||
}))
|
||||
})
|
||||
```
|
||||
|
||||
#### List of functions:
|
||||
@@ -238,7 +238,7 @@ func Trim(str, chars string) string
|
||||
func Truncate(str string, length int, ending string) string
|
||||
func TruncatingErrorf(str string, args ...interface{}) error
|
||||
func UnderscoreToCamelCase(s string) string
|
||||
func ValidateMap(s map[string]interface{}, m map[string]interface{}) (bool, error)
|
||||
func ValidateMap(inputMap map[string]interface{}, validationMap map[string]interface{}) (bool, error)
|
||||
func ValidateStruct(s interface{}) (bool, error)
|
||||
func WhiteList(str, chars string) string
|
||||
type ConditionIterator
|
||||
@@ -461,7 +461,7 @@ var inputMap = map[string]interface{}{
|
||||
},
|
||||
}
|
||||
|
||||
result, err := govalidator.ValidateMap(mapTemplate, inputMap)
|
||||
result, err := govalidator.ValidateMap(inputMap, mapTemplate)
|
||||
if err != nil {
|
||||
println("error: " + err.Error())
|
||||
}
|
||||
@@ -487,7 +487,7 @@ type StructWithCustomByteArray struct {
|
||||
CustomMinLength int `valid:"-"`
|
||||
}
|
||||
|
||||
govalidator.CustomTypeTagMap.Set("customByteArrayValidator", CustomTypeValidator(func(i interface{}, context interface{}) bool {
|
||||
govalidator.CustomTypeTagMap.Set("customByteArrayValidator", func(i interface{}, context interface{}) bool {
|
||||
switch v := context.(type) { // you can type switch on the context interface being validated
|
||||
case StructWithCustomByteArray:
|
||||
// you can check and validate against some other field in the context,
|
||||
@@ -507,14 +507,25 @@ govalidator.CustomTypeTagMap.Set("customByteArrayValidator", CustomTypeValidator
|
||||
}
|
||||
}
|
||||
return false
|
||||
}))
|
||||
govalidator.CustomTypeTagMap.Set("customMinLengthValidator", CustomTypeValidator(func(i interface{}, context interface{}) bool {
|
||||
})
|
||||
govalidator.CustomTypeTagMap.Set("customMinLengthValidator", func(i interface{}, context interface{}) bool {
|
||||
switch v := context.(type) { // this validates a field against the value in another field, i.e. dependent validation
|
||||
case StructWithCustomByteArray:
|
||||
return len(v.ID) >= v.CustomMinLength
|
||||
}
|
||||
return false
|
||||
}))
|
||||
})
|
||||
```
|
||||
|
||||
###### Loop over Error()
|
||||
By default .Error() returns all errors in a single String. To access each error you can do this:
|
||||
```go
|
||||
if err != nil {
|
||||
errs := err.(govalidator.Errors).Errors()
|
||||
for _, e := range errs {
|
||||
fmt.Println(e.Error())
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
###### Custom error messages
|
||||
@@ -602,4 +613,4 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
||||
|
||||
|
||||
## License
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fasaskevich%2Fgovalidator?ref=badge_large)
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fasaskevich%2Fgovalidator?ref=badge_large)
|
||||
|
||||
6
vendor/github.com/asaskevich/govalidator/error.go
generated
vendored
6
vendor/github.com/asaskevich/govalidator/error.go
generated
vendored
@@ -1,6 +1,9 @@
|
||||
package govalidator
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Errors is an array of multiple errors and conforms to the error interface.
|
||||
type Errors []error
|
||||
@@ -15,6 +18,7 @@ func (es Errors) Error() string {
|
||||
for _, e := range es {
|
||||
errs = append(errs, e.Error())
|
||||
}
|
||||
sort.Strings(errs)
|
||||
return strings.Join(errs, ";")
|
||||
}
|
||||
|
||||
|
||||
2
vendor/github.com/asaskevich/govalidator/patterns.go
generated
vendored
2
vendor/github.com/asaskevich/govalidator/patterns.go
generated
vendored
@@ -48,6 +48,7 @@ const (
|
||||
hasUpperCase string = ".*[[:upper:]]"
|
||||
hasWhitespace string = ".*[[:space:]]"
|
||||
hasWhitespaceOnly string = "^[[:space:]]+$"
|
||||
IMEI string = "^[0-9a-f]{14}$|^\\d{15}$|^\\d{18}$"
|
||||
)
|
||||
|
||||
// Used by IsFilePath func
|
||||
@@ -100,4 +101,5 @@ var (
|
||||
rxHasUpperCase = regexp.MustCompile(hasUpperCase)
|
||||
rxHasWhitespace = regexp.MustCompile(hasWhitespace)
|
||||
rxHasWhitespaceOnly = regexp.MustCompile(hasWhitespaceOnly)
|
||||
rxIMEI = regexp.MustCompile(IMEI)
|
||||
)
|
||||
|
||||
1
vendor/github.com/asaskevich/govalidator/types.go
generated
vendored
1
vendor/github.com/asaskevich/govalidator/types.go
generated
vendored
@@ -162,6 +162,7 @@ var TagMap = map[string]Validator{
|
||||
"ISO3166Alpha2": IsISO3166Alpha2,
|
||||
"ISO3166Alpha3": IsISO3166Alpha3,
|
||||
"ISO4217": IsISO4217,
|
||||
"IMEI": IsIMEI,
|
||||
}
|
||||
|
||||
// ISO3166Entry stores country codes
|
||||
|
||||
20
vendor/github.com/asaskevich/govalidator/validator.go
generated
vendored
20
vendor/github.com/asaskevich/govalidator/validator.go
generated
vendored
@@ -282,7 +282,7 @@ func HasLowerCase(str string) bool {
|
||||
return rxHasLowerCase.MatchString(str)
|
||||
}
|
||||
|
||||
// HasUpperCase check if the string contians as least 1 uppercase. Empty string is valid.
|
||||
// HasUpperCase check if the string contains as least 1 uppercase. Empty string is valid.
|
||||
func HasUpperCase(str string) bool {
|
||||
if IsNull(str) {
|
||||
return true
|
||||
@@ -575,7 +575,7 @@ func IsDNSName(str string) bool {
|
||||
// IsHash checks if a string is a hash of type algorithm.
|
||||
// Algorithm is one of ['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']
|
||||
func IsHash(str string, algorithm string) bool {
|
||||
len := "0"
|
||||
var len string
|
||||
algo := strings.ToLower(algorithm)
|
||||
|
||||
if algo == "crc32" || algo == "crc32b" {
|
||||
@@ -737,6 +737,11 @@ func IsLongitude(str string) bool {
|
||||
return rxLongitude.MatchString(str)
|
||||
}
|
||||
|
||||
// IsIMEI check if a string is valid IMEI
|
||||
func IsIMEI(str string) bool {
|
||||
return rxIMEI.MatchString(str)
|
||||
}
|
||||
|
||||
// IsRsaPublicKey check if a string is valid public key with provided length
|
||||
func IsRsaPublicKey(str string, keylen int) bool {
|
||||
bb := bytes.NewBufferString(str)
|
||||
@@ -808,8 +813,9 @@ func PrependPathToErrors(err error, path string) error {
|
||||
|
||||
// ValidateMap use validation map for fields.
|
||||
// result will be equal to `false` if there are any errors.
|
||||
// m is the validation map in the form
|
||||
// map[string]interface{}{"name":"required,alpha","address":map[string]interface{}{"line1":"required,alphanum"}}
|
||||
// s is the map containing the data to be validated.
|
||||
// m is the validation map in the form:
|
||||
// map[string]interface{}{"name":"required,alpha","address":map[string]interface{}{"line1":"required,alphanum"}}
|
||||
func ValidateMap(s map[string]interface{}, m map[string]interface{}) (bool, error) {
|
||||
if s == nil {
|
||||
return true, nil
|
||||
@@ -1498,11 +1504,11 @@ func ErrorsByField(e error) map[string]string {
|
||||
}
|
||||
// prototype for ValidateStruct
|
||||
|
||||
switch e.(type) {
|
||||
switch e := e.(type) {
|
||||
case Error:
|
||||
m[e.(Error).Name] = e.(Error).Err.Error()
|
||||
m[e.Name] = e.Err.Error()
|
||||
case Errors:
|
||||
for _, item := range e.(Errors).Errors() {
|
||||
for _, item := range e.Errors() {
|
||||
n := ErrorsByField(item)
|
||||
for k, v := range n {
|
||||
m[k] = v
|
||||
|
||||
Reference in New Issue
Block a user