GET请求
// get请求参数
s.BindHandler("GET:/test", func(r *ghttp.Request) {
username := r.GetString("username")
age := r.GetInt("age")
height := r.GetFloat64("height")
weight := r.GetFloat64("weight")
var info = struct{
UserName string `json:"username"`
Age int `json:"age"`
Height float64 `json:"height"`
Weight float64 `json:"weight"`
}{
username, age, height, weight,
}
r.Response.WriteJson(info)
})
POST请求
// post请求参数
s.BindHandler("POST:/test", func(r *ghttp.Request) {
username := r.GetPostString("username")
age := r.GetPostInt("age")
height := r.GetPostFloat64("height")
weight := r.GetPostFloat64("weight")
var info = struct{
UserName string `json:"username"`
Age int `json:"age"`
Height float64 `json:"height"`
Weight float64 `json:"weight"`
}{
username, age, height, weight,
}
r.Response.WriteJson(info)
})