gf/.example/net/ghttp/server/request/request_struct.go

30 lines
620 B
Go
Raw Normal View History

package main
import (
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
func main() {
type User struct {
Uid int `json:"uid"`
Name string `json:"name" p:"username"`
Pass1 string `json:"pass1" p:"password1"`
Pass2 string `json:"pass2" p:"password2"`
}
2019-04-03 00:03:46 +08:00
s := g.Server()
s.BindHandler("/user", func(r *ghttp.Request) {
var user *User
if err := r.Parse(&user); err != nil {
panic(err)
}
2019-04-03 00:03:46 +08:00
r.Response.WriteJson(user)
})
s.SetPort(8199)
s.Run()
2019-04-03 00:03:46 +08:00
// http://127.0.0.1:8199/user?uid=1&name=john&password1=123&userpass2=123
// {"name":"john","pass1":"123","pass2":"123","uid":1}
}