代码拉取完成,页面将自动刷新
package main
import (
"github.com/kataras/iris"
"github.com/betacraft/yaag/irisyaag"
"github.com/betacraft/yaag/yaag"
)
/*
go get github.com/betacraft/yaag/...
*/
type myXML struct {
Result string `xml:"result"`
}
func main() {
app := iris.New()
yaag.Init(&yaag.Config{ // <- IMPORTANT, init the middleware.
On: true,
DocTitle: "Iris",
DocPath: "apidoc.html",
BaseUrls: map[string]string{"Production": "", "Staging": ""},
})
app.Use(irisyaag.New()) // <- IMPORTANT, register the middleware.
app.Get("/json", func(ctx iris.Context) {
ctx.JSON(iris.Map{"result": "Hello World!"})
})
app.Get("/plain", func(ctx iris.Context) {
ctx.Text("Hello World!")
})
app.Get("/xml", func(ctx iris.Context) {
ctx.XML(myXML{Result: "Hello World!"})
})
app.Get("/complex", func(ctx iris.Context) {
value := ctx.URLParam("key")
ctx.JSON(iris.Map{"value": value})
})
// Run our HTTP Server.
//
// Documentation of "yaag" doesn't note the follow, but in Iris we are careful on what
// we provide to you.
//
// Each incoming request results on re-generation and update of the "apidoc.html" file.
// Recommentation:
// Write tests that calls those handlers, save the generated "apidoc.html".
// Turn off the yaag middleware when in production.
//
// Example usage:
// Visit all paths and open the generated "apidoc.html" file to see the API's automated docs.
app.Run(iris.Addr(":8080"))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。