2017-03-24 00:22:05 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-10-25 01:27:02 +03:00
|
|
|
"github.com/kataras/iris/v12"
|
2017-07-10 18:32:42 +03:00
|
|
|
|
2019-10-25 01:27:02 +03:00
|
|
|
"github.com/kataras/iris/v12/sessions"
|
2017-03-24 00:22:05 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
2020-05-07 07:34:17 +03:00
|
|
|
|
|
|
|
sess := sessions.New(sessions.Config{Cookie: "_session_id", AllowReclaim: true})
|
|
|
|
app.Use(sess.Handler())
|
2017-03-24 00:22:05 +02:00
|
|
|
|
2017-08-27 20:35:23 +03:00
|
|
|
app.Get("/set", func(ctx iris.Context) {
|
2020-05-07 07:34:17 +03:00
|
|
|
s := sessions.Get(ctx)
|
2017-07-10 18:32:42 +03:00
|
|
|
s.SetFlash("name", "iris")
|
2019-06-07 21:07:08 +03:00
|
|
|
ctx.Writef("Message set, is available for the next request")
|
2017-03-24 00:22:05 +02:00
|
|
|
})
|
|
|
|
|
2017-08-27 20:35:23 +03:00
|
|
|
app.Get("/get", func(ctx iris.Context) {
|
2020-05-07 07:34:17 +03:00
|
|
|
s := sessions.Get(ctx)
|
2017-07-10 18:32:42 +03:00
|
|
|
name := s.GetFlashString("name")
|
2017-04-17 17:20:14 +08:00
|
|
|
if name == "" {
|
2017-03-24 00:22:05 +02:00
|
|
|
ctx.Writef("Empty name!!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Writef("Hello %s", name)
|
|
|
|
})
|
|
|
|
|
2017-08-27 20:35:23 +03:00
|
|
|
app.Get("/test", func(ctx iris.Context) {
|
2020-05-07 07:34:17 +03:00
|
|
|
s := sessions.Get(ctx)
|
2017-07-10 18:32:42 +03:00
|
|
|
name := s.GetFlashString("name")
|
2017-04-17 17:20:14 +08:00
|
|
|
if name == "" {
|
2017-03-24 00:22:05 +02:00
|
|
|
ctx.Writef("Empty name!!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-07-10 18:32:42 +03:00
|
|
|
ctx.Writef("Ok you are coming from /set ,the value of the name is %s", name)
|
2017-03-24 00:22:05 +02:00
|
|
|
ctx.Writef(", and again from the same context: %s", name)
|
|
|
|
})
|
|
|
|
|
2020-03-05 22:41:27 +02:00
|
|
|
app.Listen(":8080")
|
2017-03-24 00:22:05 +02:00
|
|
|
}
|