diff options
author | 2024-03-11 10:12:06 +0000 | |
---|---|---|
committer | 2024-03-11 10:12:06 +0000 | |
commit | e24efcac8b67baa9454bf27631e5e49f898a88d4 (patch) | |
tree | d9adec2f05e1d8714edee66062a4b95a81ee2a61 /vendor/github.com/go-playground/validator/v10/util.go | |
parent | [bugfix] Fix whitespace move_id issue (#2742) (diff) | |
download | gotosocial-e24efcac8b67baa9454bf27631e5e49f898a88d4.tar.xz |
[chore]: Bump github.com/gin-contrib/cors from 1.5.0 to 1.7.0 (#2745)
Diffstat (limited to 'vendor/github.com/go-playground/validator/v10/util.go')
-rw-r--r-- | vendor/github.com/go-playground/validator/v10/util.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/vendor/github.com/go-playground/validator/v10/util.go b/vendor/github.com/go-playground/validator/v10/util.go index 4bd947bdf..16851593d 100644 --- a/vendor/github.com/go-playground/validator/v10/util.go +++ b/vendor/github.com/go-playground/validator/v10/util.go @@ -1,7 +1,9 @@ package validator import ( + "fmt" "reflect" + "regexp" "strconv" "strings" "time" @@ -292,3 +294,18 @@ func panicIf(err error) { panic(err.Error()) } } + +// Checks if field value matches regex. If fl.Field can be cast to Stringer, it uses the Stringer interfaces +// String() return value. Otherwise, it uses fl.Field's String() value. +func fieldMatchesRegexByStringerValOrString(regex *regexp.Regexp, fl FieldLevel) bool { + switch fl.Field().Kind() { + case reflect.String: + return regex.MatchString(fl.Field().String()) + default: + if stringer, ok := fl.Field().Interface().(fmt.Stringer); ok { + return regex.MatchString(stringer.String()) + } else { + return regex.MatchString(fl.Field().String()) + } + } +} |