5
0
Prechádzať zdrojové kódy

fix:修复数据验证错误

liuyaqi 3 rokov pred
rodič
commit
376bb75cc5
1 zmenil súbory, kde vykonal 12 pridanie a 0 odobranie
  1. 12 0
      valid/valid.go

+ 12 - 0
valid/valid.go

@@ -2,6 +2,7 @@ package valid
 
 import (
 	"context"
+	"reflect"
 	"strings"
 
 	"github.com/gogf/gf/errors/gerror"
@@ -17,6 +18,17 @@ func init() {
 
 func IntInChecker(ctx context.Context, rule string, value interface{}, message string, data interface{}) error {
 	// rule int-in:1,2
+	// fmt.Println(rule, value, value == nil)
+	if value == nil {
+		return nil
+	}
+	reflectValue := reflect.ValueOf(value)
+	if reflectValue.Kind() == reflect.Ptr {
+		if reflectValue.IsNil() {
+			return nil
+		}
+	}
+
 	v := gconv.String(value)
 	allow := strings.Split(rule, ":")
 	if len(allow) < 2 {