1 Star 2 Fork 0

api-go/iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 974 Bytes
一键复制 编辑 原始数据 按行查看 历史
kataras 提交于 2017-11-05 10:12 +08:00 . Update to version 8.5.6 | Read HISTORY.md
package main
// $ go get github.com/rs/cors
// $ go run main.go
import (
"github.com/kataras/iris"
"github.com/iris-contrib/middleware/cors"
)
func main() {
app := iris.New()
crs := cors.New(cors.Options{
AllowedOrigins: []string{"*"}, // allows everything, use that to change the hosts.
AllowCredentials: true,
})
v1 := app.Party("/api/v1")
v1.Use(crs)
{
v1.Get("/home", func(ctx iris.Context) {
ctx.WriteString("Hello from /home")
})
v1.Get("/about", func(ctx iris.Context) {
ctx.WriteString("Hello from /about")
})
v1.Post("/send", func(ctx iris.Context) {
ctx.WriteString("sent")
})
}
// or use that to wrap the entire router
// even before the path and method matching
// this should work better and with all cors' features.
// Use that instead, if suits you.
// app.WrapRouter(cors.WrapNext(cors.Options{
// AllowedOrigins: []string{"*"},
// AllowCredentials: true,
// }))
app.Run(iris.Addr("localhost:8080"))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/netscript/iris.git
git@gitee.com:netscript/iris.git
netscript
iris
iris
v8.5.9

搜索帮助