Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

所有接口好像都没有做入参验证? #9

Open
GeniusZzzz opened this issue Feb 7, 2024 · 1 comment
Open

所有接口好像都没有做入参验证? #9

GeniusZzzz opened this issue Feb 7, 2024 · 1 comment

Comments

@GeniusZzzz
Copy link

No description provided.

@huanglishi
Copy link
Owner

如果需要验证参数先移步企业版,开源暂时没有。

// 测试入参验证
func (api *Index) SaveVeriApi(c *gf.GinCtx) {
    //获取传参
    param, _ := gf.RequestParam(c)
    //验证规则
    rules := map[string]string{
        "account":   "bail|required|length:6,16|same:qq",
        "password":  "required|same:password2",
        "password2": "required",
    }
    if err := gf.Validator().Rules(rules).Data(param).Locale(gconv.String(param["locale"])).Run(c); err != nil {
        gf.Failed().SetMsg(err.String()).Regin(c)
        return
    }
    res, err := gf.Model("user").Data(param).Save()
    if err != nil {
        gf.Failed().SetMsg("错误").SetData(err).Regin(c)
    } else {
        gf.Success().SetMsg("添加成功").SetData(res).SetExdata(param).Regin(c)
    }
}

更多请到文档查看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants