summaryrefslogtreecommitdiff
path: root/internal/gtsmodel/validate.go
diff options
context:
space:
mode:
authorLibravatar tsmethurst <tobi.smethurst@protonmail.com>2021-08-30 20:20:27 +0200
committerLibravatar tsmethurst <tobi.smethurst@protonmail.com>2021-09-01 11:11:26 +0200
commit356d28fef9167ba1ec37ecc1a547196e78e56089 (patch)
treea06b67ecc9860ebf058c94aa10a6796393fc5b96 /internal/gtsmodel/validate.go
parentmore work on struct validation (diff)
downloadgotosocial-356d28fef9167ba1ec37ecc1a547196e78e56089.tar.xz
more work on struct validation
Diffstat (limited to 'internal/gtsmodel/validate.go')
-rw-r--r--internal/gtsmodel/validate.go17
1 files changed, 6 insertions, 11 deletions
diff --git a/internal/gtsmodel/validate.go b/internal/gtsmodel/validate.go
index 720aad463..da9f6d3eb 100644
--- a/internal/gtsmodel/validate.go
+++ b/internal/gtsmodel/validate.go
@@ -32,20 +32,15 @@ const (
InvalidValidationPanic = "validate function was passed invalid item"
)
-var ulidValidator = func(fl validator.FieldLevel) bool {
- value, kind, _ := fl.ExtractType(fl.Field())
+func ulidValidator(fl validator.FieldLevel) bool {
+ field := fl.Field()
- if kind != reflect.String {
+ switch field.Kind() {
+ case reflect.String:
+ return util.ValidateULID(field.String())
+ default:
return false
}
-
- // we want either an empty string, or a proper ULID, nothing else
- // if the string is empty, the `required` tag will take care of it so we don't need to worry about it here
- s := value.String()
- if len(s) == 0 {
- return true
- }
- return util.ValidateULID(s)
}
func init() {