在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
About gomagicgomagic is a middleware magicbox,it is not a framework,but a collection of useful middleware Web Magic Useage$ go get github.com/scottkiss/gomagic/webmagic package mainimport ( "github.com/scottkiss/gomagic/webmagic" "log")func main() { app := webmagic.Application() //handler get request //eg. http://localhost:8888/hello/100 app.Get("/hello/:id", handler) //handler get request app.Get("/world/:id", handlerXml) //handler post request app.Post("/post", handlerPost) app.Run(":8888")}type User struct { Id string Name string}//response jsonfunc handler(ctx *webmagic.Context) { id := ctx.PathParam("id") log.Println(id) user := &User{Id: id, Name: "hello"} ctx.Output.Json(user, true)}//response xmlfunc handlerXml(ctx *webmagic.Context) { id := ctx.PathParam("id") log.Println(id) user := &User{Id: id, Name: "world"} ctx.Output.Xml(user)}func handlerPost(ctx *webmagic.Context) { user := &User{} ctx.Input.ReadJson(user) ctx.Output.Json(user, true)} LicenseView the LICENSE file |
请发表评论