diff --git a/run.go b/run.go index b060c28..1e8f0c5 100644 --- a/run.go +++ b/run.go @@ -153,6 +153,11 @@ func getDataStatus(val gjson.Result, dataType string) string { if len(val.Map()) == 0 { return consts.DataStatusIsEmpty } + } else if strings.HasPrefix(dataType, "*") { + // 指针类型 + if nil == val.Value() { + return consts.DataStatusIsNil + } } } return "" diff --git a/run_test.go b/run_test.go index b3581e0..989110b 100644 --- a/run_test.go +++ b/run_test.go @@ -10,6 +10,8 @@ package validator import ( "encoding/json" "fmt" + "github.com/stretchr/testify/assert" + "github.com/tidwall/gjson" "testing" ) @@ -21,3 +23,22 @@ func TestRun(t *testing.T) { byteData, _ := json.Marshal(sourceData) fmt.Println(string(byteData)) } + +func Test_getDataStatus(t *testing.T) { + type args struct { + val gjson.Result + dataType string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equalf(t, tt.want, getDataStatus(tt.args.val, tt.args.dataType), "getDataStatus(%v, %v)", tt.args.val, tt.args.dataType) + }) + } +}