基础类型, 无嵌套匿名结构体生成, 待解决寻址问题

This commit is contained in:
2025-03-18 18:43:45 +08:00
parent 393af3c4c3
commit 6b5bfaf666
5 changed files with 338 additions and 10 deletions

48
validate_test.go Normal file
View 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)
}