基础类型, 无嵌套匿名结构体生成, 待解决寻址问题
This commit is contained in:
48
validate_test.go
Normal file
48
validate_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
// Package validate ...
|
||||
//
|
||||
// Description : validate ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2025-03-18 17:36
|
||||
package validate
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestRun_Simple_Data 无嵌套、无复杂数据类型的处理
|
||||
func TestRun_Simple_Data(t *testing.T) {
|
||||
testMap := map[string]any{
|
||||
"age": 180,
|
||||
"height": 179.5,
|
||||
"name": "baicha",
|
||||
}
|
||||
sourceByteData, _ := json.Marshal(testMap)
|
||||
fieldList := []StructField{
|
||||
{
|
||||
JsonTag: "age",
|
||||
Type: consts.DataTypeInt,
|
||||
Required: false,
|
||||
RuleList: []Rule{
|
||||
{
|
||||
Tag: "min",
|
||||
Args: []string{"1"},
|
||||
},
|
||||
{
|
||||
Tag: "max",
|
||||
Args: []string{"20"},
|
||||
},
|
||||
},
|
||||
DefaultValue: "",
|
||||
SourcePath: "age",
|
||||
TargetPath: "user_age",
|
||||
Errmsg: "年龄必须在[1,20]之间",
|
||||
},
|
||||
}
|
||||
_, err := Run(sourceByteData, fieldList)
|
||||
fmt.Println(err)
|
||||
}
|
Reference in New Issue
Block a user