mirror of
https://gitee.com/johng/gf
synced 2026-07-07 06:15:15 +08:00
完善代码示例
This commit is contained in:
@ -4,7 +4,6 @@ import (
|
||||
"gitee.com/johng/gf/g"
|
||||
"gitee.com/johng/gf/g/net/ghttp"
|
||||
"gitee.com/johng/gf/g/util/gvalid"
|
||||
"gitee.com/johng/gf/g/encoding/gparser"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -19,9 +18,11 @@ func main() {
|
||||
s.BindHandler("/user", func(r *ghttp.Request){
|
||||
user := new(User)
|
||||
r.GetToStruct(user)
|
||||
result := gvalid.CheckStruct(user, nil)
|
||||
json, _ := gparser.VarToJsonIndent(result)
|
||||
r.Response.Write(json)
|
||||
if err := gvalid.CheckStruct(user, nil); err != nil {
|
||||
r.Response.WriteJson(err.Maps())
|
||||
} else {
|
||||
r.Response.Write("ok")
|
||||
}
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
|
||||
Reference in New Issue
Block a user