From 51397e9e97b1e85b36b5e35ac14565fa0d899a7b Mon Sep 17 00:00:00 2001 From: jjxu <428192774@qq.com> Date: Wed, 25 Oct 2023 11:03:50 +0800 Subject: [PATCH] fix: validatorWithNonRepeatedConstraint was returned an error result --- plugin/plugin.go | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/plugin/plugin.go b/plugin/plugin.go index 1de26e7..825d579 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -51,7 +51,6 @@ package plugin import ( "fmt" "os" - "reflect" "strconv" "strings" @@ -664,22 +663,8 @@ func (p *plugin) validatorWithNonRepeatedConstraint(fv *validator.FieldValidator return false } - // Need to use reflection in order to be future-proof for new types of constraints. - v := reflect.ValueOf(*fv) - for i := 0; i < v.NumField(); i++ { - fieldName := v.Type().Field(i).Name - - // All known validators will have a pointer type and we should skip any fields - // that are not pointers (i.e unknown fields, etc) as well as 'nil' pointers that - // don't lead to anything. - if v.Type().Field(i).Type.Kind() != reflect.Ptr || v.Field(i).IsNil() { - continue - } - - // Identify non-repeated constraints based on their name. - if fieldName != "RepeatedCountMin" && fieldName != "RepeatedCountMax" { - return true - } + if fv.RepeatedCountMin == nil && fv.RepeatedCountMax == nil { + return true } return false }