1 Star 0 Fork 0

sonysoul/iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
kataras 提交于 2017-11-05 04:12 . Update to version 8.5.6 | Read HISTORY.md
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"))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sonysoul/iris.git
git@gitee.com:sonysoul/iris.git
sonysoul
iris
iris
v10.4.0

搜索帮助

0d507c66 1850385 C8b1a773 1850385