gofream框架02 请求

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)
})
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容