mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
30 lines
672 B
Go
30 lines
672 B
Go
package main
|
|
|
|
import (
|
|
"github.com/gogf/gf/frame/g"
|
|
"github.com/gogf/gf/net/ghttp"
|
|
)
|
|
|
|
type User struct {
|
|
Uid int `json:"uid"`
|
|
Name string `json:"name" params:"username"`
|
|
Pass1 string `json:"pass1" params:"password1,userpass1"`
|
|
Pass2 string `json:"pass2" params:"password3,userpass2"`
|
|
}
|
|
|
|
func main() {
|
|
s := g.Server()
|
|
s.BindHandler("/user", func(r *ghttp.Request) {
|
|
user := new(User)
|
|
r.GetToStruct(user)
|
|
//r.GetPostToStruct(user)
|
|
//r.GetQueryToStruct(user)
|
|
r.Response.WriteJson(user)
|
|
})
|
|
s.SetPort(8199)
|
|
s.Run()
|
|
|
|
// http://127.0.0.1:8199/user?uid=1&name=john&password1=123&userpass2=123
|
|
// {"name":"john","pass1":"123","pass2":"123","uid":1}
|
|
}
|