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