1 Star 0 Fork 0

hh / iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 891 Bytes
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/sessions"
)
func main() {
app := iris.New()
sess := sessions.New(sessions.Config{Cookie: "myappsessionid"})
app.Get("/set", func(ctx iris.Context) {
s := sess.Start(ctx)
s.SetFlash("name", "iris")
ctx.Writef("Message setted, is available for the next request")
})
app.Get("/get", func(ctx iris.Context) {
s := sess.Start(ctx)
name := s.GetFlashString("name")
if name == "" {
ctx.Writef("Empty name!!")
return
}
ctx.Writef("Hello %s", name)
})
app.Get("/test", func(ctx iris.Context) {
s := sess.Start(ctx)
name := s.GetFlashString("name")
if name == "" {
ctx.Writef("Empty name!!")
return
}
ctx.Writef("Ok you are coming from /set ,the value of the name is %s", name)
ctx.Writef(", and again from the same context: %s", name)
})
app.Run(iris.Addr(":8080"))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/w1229748769/iris.git
git@gitee.com:w1229748769/iris.git
w1229748769
iris
iris
v10.5.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891