@@ -39,12 +39,12 @@ func (v *Validator) Check(value any, field string, validators ...ValidatorFunc)
|
||||
if value != nil {
|
||||
val := reflect.ValueOf(value)
|
||||
// Dereference all pointer levels
|
||||
for val.Kind() == reflect.Ptr && !val.IsNil() {
|
||||
for val.Kind() == reflect.Pointer && !val.IsNil() {
|
||||
val = val.Elem()
|
||||
actualValue = val.Interface()
|
||||
}
|
||||
// If we ended up with a nil pointer at any level, set actualValue to nil
|
||||
if val.Kind() == reflect.Ptr && val.IsNil() {
|
||||
if val.Kind() == reflect.Pointer && val.IsNil() {
|
||||
actualValue = nil
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func (v *Validator) CheckEach(items any, field string, fn func(index int, item a
|
||||
|
||||
val := reflect.ValueOf(items)
|
||||
// Dereference pointer levels to get to the actual slice
|
||||
for val.Kind() == reflect.Ptr {
|
||||
for val.Kind() == reflect.Pointer {
|
||||
if val.IsNil() {
|
||||
return
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func dereferenceValue(value any) (any, bool) {
|
||||
|
||||
val := reflect.ValueOf(value)
|
||||
// Dereference all pointer levels
|
||||
for val.Kind() == reflect.Ptr {
|
||||
for val.Kind() == reflect.Pointer {
|
||||
if val.IsNil() {
|
||||
return nil, true
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
func MinItems(min int) ValidatorFunc {
|
||||
return func(value any) *ValidationError {
|
||||
v := reflect.ValueOf(value)
|
||||
if v.Kind() == reflect.Ptr {
|
||||
if v.Kind() == reflect.Pointer {
|
||||
if v.IsNil() {
|
||||
return nil
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func MinItems(min int) ValidatorFunc {
|
||||
func MaxItems(max int) ValidatorFunc {
|
||||
return func(value any) *ValidationError {
|
||||
v := reflect.ValueOf(value)
|
||||
if v.Kind() == reflect.Ptr {
|
||||
if v.Kind() == reflect.Pointer {
|
||||
if v.IsNil() {
|
||||
return nil
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func MaxItems(max int) ValidatorFunc {
|
||||
func UniqueItems() ValidatorFunc {
|
||||
return func(value any) *ValidationError {
|
||||
v := reflect.ValueOf(value)
|
||||
if v.Kind() == reflect.Ptr {
|
||||
if v.Kind() == reflect.Pointer {
|
||||
if v.IsNil() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package validator
|
||||
import (
|
||||
"net/url"
|
||||
"regexp"
|
||||
"slices"
|
||||
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
)
|
||||
@@ -182,13 +183,7 @@ func GID(entityTypes ...uint16) ValidatorFunc {
|
||||
|
||||
if len(entityTypes) > 0 {
|
||||
parsedEntityType := gidValue.EntityType()
|
||||
valid := false
|
||||
for _, expected := range entityTypes {
|
||||
if parsedEntityType == expected {
|
||||
valid = true
|
||||
break
|
||||
}
|
||||
}
|
||||
valid := slices.Contains(entityTypes, parsedEntityType)
|
||||
if !valid {
|
||||
return newValidationError(ErrorCodeInvalidGID, "GID has invalid entity type")
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func OneOfSlice[T any](allowed []T) ValidatorFunc {
|
||||
// Dereference all pointer levels
|
||||
actualValue := value
|
||||
val := reflect.ValueOf(value)
|
||||
for val.Kind() == reflect.Ptr {
|
||||
for val.Kind() == reflect.Pointer {
|
||||
if val.IsNil() {
|
||||
return nil
|
||||
}
|
||||
@@ -247,7 +247,7 @@ func NotOneOfSlice[T any](disallowed []T) ValidatorFunc {
|
||||
// Dereference all pointer levels
|
||||
actualValue := value
|
||||
val := reflect.ValueOf(value)
|
||||
for val.Kind() == reflect.Ptr {
|
||||
for val.Kind() == reflect.Pointer {
|
||||
if val.IsNil() {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user