mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
organise sessions examples
Former-commit-id: 682472d2cf4ebfc740687522fe5eef77b5bb1a72
This commit is contained in:
@@ -8,16 +8,18 @@ import (
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
sess := sessions.New(sessions.Config{Cookie: "myappsessionid", AllowReclaim: true})
|
||||
|
||||
sess := sessions.New(sessions.Config{Cookie: "_session_id", AllowReclaim: true})
|
||||
app.Use(sess.Handler())
|
||||
|
||||
app.Get("/set", func(ctx iris.Context) {
|
||||
s := sess.Start(ctx)
|
||||
s := sessions.Get(ctx)
|
||||
s.SetFlash("name", "iris")
|
||||
ctx.Writef("Message set, is available for the next request")
|
||||
})
|
||||
|
||||
app.Get("/get", func(ctx iris.Context) {
|
||||
s := sess.Start(ctx)
|
||||
s := sessions.Get(ctx)
|
||||
name := s.GetFlashString("name")
|
||||
if name == "" {
|
||||
ctx.Writef("Empty name!!")
|
||||
@@ -27,7 +29,7 @@ func main() {
|
||||
})
|
||||
|
||||
app.Get("/test", func(ctx iris.Context) {
|
||||
s := sess.Start(ctx)
|
||||
s := sessions.Get(ctx)
|
||||
name := s.GetFlashString("name")
|
||||
if name == "" {
|
||||
ctx.Writef("Empty name!!")
|
||||
|
||||
Reference in New Issue
Block a user