forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (34 loc) · 911 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/sessions"
)
func main() {
app := iris.New()
sess := sessions.New(sessions.Config{Cookie: "myappsessionid", AllowReclaim: true})
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"))
}