增加指针 nil 验证
This commit is contained in:
		
							
								
								
									
										5
									
								
								run.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								run.go
									
									
									
									
									
								
							@ -153,6 +153,11 @@ func getDataStatus(val gjson.Result, dataType string) string {
 | 
				
			|||||||
			if len(val.Map()) == 0 {
 | 
								if len(val.Map()) == 0 {
 | 
				
			||||||
				return consts.DataStatusIsEmpty
 | 
									return consts.DataStatusIsEmpty
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							} else if strings.HasPrefix(dataType, "*") {
 | 
				
			||||||
 | 
								// 指针类型
 | 
				
			||||||
 | 
								if nil == val.Value() {
 | 
				
			||||||
 | 
									return consts.DataStatusIsNil
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return ""
 | 
						return ""
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										21
									
								
								run_test.go
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								run_test.go
									
									
									
									
									
								
							@ -10,6 +10,8 @@ package validator
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"github.com/stretchr/testify/assert"
 | 
				
			||||||
 | 
						"github.com/tidwall/gjson"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -21,3 +23,22 @@ func TestRun(t *testing.T) {
 | 
				
			|||||||
	byteData, _ := json.Marshal(sourceData)
 | 
						byteData, _ := json.Marshal(sourceData)
 | 
				
			||||||
	fmt.Println(string(byteData))
 | 
						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)
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user