github.com/gogf/gf@v1.16.9/.example/net/ghttp/server/request/request_struct.go (about) 1 package main 2 3 import ( 4 "github.com/gogf/gf/frame/g" 5 "github.com/gogf/gf/net/ghttp" 6 ) 7 8 func main() { 9 type User struct { 10 Uid int `json:"uid"` 11 Name string `json:"name" p:"username"` 12 Pass1 string `json:"pass1" p:"password1"` 13 Pass2 string `json:"pass2" p:"password2"` 14 } 15 16 s := g.Server() 17 s.BindHandler("/user", func(r *ghttp.Request) { 18 var user *User 19 if err := r.Parse(&user); err != nil { 20 panic(err) 21 } 22 r.Response.WriteJson(user) 23 }) 24 s.SetPort(8199) 25 s.Run() 26 27 // http://127.0.0.1:8199/user?uid=1&name=john&password1=123&userpass2=123 28 // {"name":"john","pass1":"123","pass2":"123","uid":1} 29 }