格式化验证失败的错误信息, 默认tag=err, 支持重置默认tag

This commit is contained in:
2025-02-07 18:01:05 +08:00
parent a338713c77
commit 7c67160c65
4 changed files with 84 additions and 1 deletions

View File

@ -21,7 +21,7 @@ func (t TestController) Logic(ctx *gin.Context, formData *TestForm) (any, error)
type TestForm struct {
Meta `tag:"测试表单" path:"/a/b/c/d" desc:"测试接口" method:"get"`
Age int `json:"age" form:"age" binding:"min=20"`
Age int `json:"age" form:"age" binding:"min=20" err_msg:"年龄不能小于20"`
Name string `json:"name" form:"name"`
Test *Test `json:"test" form:"test"`
Num *int64 `json:"num" form:"num"`
@ -31,6 +31,7 @@ type Test struct {
}
func Test_parseController(t *testing.T) {
SetValidateErrTag("err_msg")
r := gin.Default()
Group(r, "test", nil, TestController{})
r.Run(":8080")