381 Star 2.5K Fork 616

GVPJohn / gf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
request_validation.go 848 Bytes
一键复制 编辑 原始数据 按行查看 历史
John 提交于 2018-11-26 09:33 . 完善代码示例
package main
import (
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/net/ghttp"
"gitee.com/johng/gf/g/util/gvalid"
)
func main() {
type User struct {
Uid int `gvalid:"uid@min:1"`
Name string `params:"username" gvalid:"username @required|length:6,30"`
Pass1 string `params:"password1" gvalid:"password1@required|password3"`
Pass2 string `params:"password2" gvalid:"password2@required|password3|same:password1#||两次密码不一致,请重新输入"`
}
s := g.Server()
s.BindHandler("/user", func(r *ghttp.Request){
user := new(User)
r.GetToStruct(user)
if err := gvalid.CheckStruct(user, nil); err != nil {
r.Response.WriteJson(err.Maps())
} else {
r.Response.Write("ok")
}
})
s.SetPort(8199)
s.Run()
}
Go
1
https://gitee.com/johng/gf.git
git@gitee.com:johng/gf.git
johng
gf
gf
v1.4.7

搜索帮助