From 356d28fef9167ba1ec37ecc1a547196e78e56089 Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Mon, 30 Aug 2021 20:20:27 +0200 Subject: more work on struct validation --- internal/gtsmodel/validate.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'internal/gtsmodel/validate.go') 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() { -- cgit v1.2.3