1 Star 0 Fork 0

hh/iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1018 Bytes
一键复制 编辑 原始数据 按行查看 历史
// Package main shows how you can add middleware to an mvc Application, simply
// by using its `Router` which is a sub router(an iris.Party) of the main iris app.
package main
import (
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/cache"
"github.com/kataras/iris/mvc"
)
var cacheHandler = cache.Handler(10 * time.Second)
func main() {
app := iris.New()
mvc.Configure(app, configure)
// http://localhost:8080
// http://localhost:8080/other
//
// refresh every 10 seconds and you'll see different time output.
app.Run(iris.Addr(":8080"))
}
func configure(m *mvc.Application) {
m.Router.Use(cacheHandler)
m.Handle(&exampleController{
timeFormat: "Mon, Jan 02 2006 15:04:05",
})
}
type exampleController struct {
timeFormat string
}
func (c *exampleController) Get() string {
now := time.Now().Format(c.timeFormat)
return "last time executed without cache: " + now
}
func (c *exampleController) GetOther() string {
now := time.Now().Format(c.timeFormat)
return "/other: " + now
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/w1229748769/iris.git
git@gitee.com:w1229748769/iris.git
w1229748769
iris
iris
v10.6.5

搜索帮助