Ai
1 Star 1 Fork 0

tianyuliang/iris

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
main.go 809 Bytes
Copy Edit Raw Blame History
kataras authored 2017-06-04 04:22 +08:00 . Publish the new version :airplane:| Look description please!
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
type Company struct {
Name string
City string
Other string
}
func MyHandler(ctx context.Context) {
c := &Company{}
if err := ctx.ReadJSON(c); err != nil {
ctx.StatusCode(iris.StatusBadRequest)
ctx.WriteString(err.Error())
return
}
ctx.Writef("Received: %#v\n", c)
}
func main() {
app := iris.New()
app.Post("/", MyHandler)
// use Postman or whatever to do a POST request
// to the http://localhost:8080 with RAW BODY:
/*
{
"Name": "Iris-Go",
"City": "New York",
"Other": "Something here"
}
*/
// and Content-Type to application/json
//
// The response should be:
// Received: &main.Company{Name:"Iris-Go", City:"New York", Other:"Something here"}
app.Run(iris.Addr(":8080"))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tianyuliang/iris.git
git@gitee.com:tianyuliang/iris.git
tianyuliang
iris
iris
20f30022705b

Search