1 Star 1 Fork 0

teamlint/iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
venjiang 提交于 2018-08-14 10:08 . update to iris version 10.7.0
package main
import (
"time"
"github.com/teamlint/iris/_examples/hero/sessions/routes"
"github.com/teamlint/iris"
"github.com/teamlint/iris/hero" // <- IMPORTANT
"github.com/teamlint/iris/sessions"
)
func main() {
app := iris.New()
sessionManager := sessions.New(sessions.Config{
Cookie: "site_session_id",
Expires: 60 * time.Minute,
AllowReclaim: true,
})
// Register
// dynamic dependencies like the *sessions.Session, from `sessionManager.Start(ctx) *sessions.Session` <- it accepts a Context and it returns
// something -> this is called dynamic request-time dependency and that "something" can be used to your handlers as input parameters,
// no limit about the number of dependencies, each handler will be builded once, before the server ran and it will use only dependencies that it needs.
hero.Register(sessionManager.Start)
// convert any function to an iris Handler, their input parameters are being resolved using the unique Iris' blazing-fast dependency injection
// for services or dynamic dependencies like the *sessions.Session, from sessionManager.Start(ctx) *sessions.Session) <- it accepts a context and it returns
// something-> this is called dynamic request-time dependency.
indexHandler := hero.Handler(routes.Index)
// Method: GET
// Path: http://localhost:8080
app.Get("/", indexHandler)
app.Run(
iris.Addr(":8080"),
iris.WithoutVersionChecker,
iris.WithoutServerError(iris.ErrServerClosed),
)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/teamlint/iris.git
git@gitee.com:teamlint/iris.git
teamlint
iris
iris
v10.7.0

搜索帮助