004-Go iris 接收post json数据

时间:2018-04-03 22:05:43   收藏:0   阅读:5619
package main

import(
    "github.com/kataras/iris"
    "github.com/kataras/iris/middleware/logger"
    "github.com/kataras/iris/middleware/recover"
)

type User struct{
    Name    string `json:"name"`
    Age        int    `json:"age"`
}

func main(){
    app := iris.New()
    
    app.Logger().SetLevel("debug")

    app.Use(recover.New())
    app.Use(logger.New())

    app.Post("/user", func(ctx iris.Context){
        c := &User{}

        if err := ctx.ReadJSON(c); err != nil{
            panic(err.Error())
        }else{
            ctx.JSON(c)
        }
    })
    

    app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!