数据源不存在指定数据,生成目标结构体也需要生成对应的结构体,否则会丢失相关参数验证

This commit is contained in:
2025-03-21 16:48:16 +08:00
parent 0754f879e8
commit be6b8e644f
3 changed files with 74 additions and 14 deletions

View File

@ -50,6 +50,39 @@ func TestRun_Simple_Data(t *testing.T) {
TargetPath: "user_age",
Errmsg: "年龄必须在[1,2000]之间",
},
{
JsonTag: "company_name",
Type: consts.DataTypeString,
Required: false,
RuleList: []Rule{
{
Tag: "min",
Args: []string{"1"},
},
{
Tag: "max",
Args: []string{"20"},
},
},
DefaultValue: "",
SourcePath: "company.name",
TargetPath: "company.cname",
Errmsg: "公司名称必须在[1,20]之间",
},
{
JsonTag: "company",
Type: consts.DataTypeString,
Required: false,
RuleList: []Rule{
{
Tag: "required",
},
},
DefaultValue: "",
SourcePath: "company",
TargetPath: "company",
Errmsg: "公司信息必传",
},
}
res, err := Run(sourceByteData, fieldList)
fmt.Println(err, string(res))