-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (40 loc) · 1.08 KB
/
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
43
44
45
46
47
48
package main
import (
"github.com/go-siris/siris"
"github.com/go-siris/siris/context"
"github.com/go-siris/siris/sessions"
)
func main() {
app := siris.New()
// output startup banner and error logs on os.Stdout
app.AttachSessionManager("memory", &sessions.ManagerConfig{
CookieName: "go-session-id",
EnableSetCookie: true,
Gclifetime: 3600,
Maxlifetime: 7200,
})
app.Get("/set", func(ctx context.Context) {
ctx.Session().Set("name", "siris")
ctx.Writef("Message set, is available for the next request")
})
app.Get("/get", func(ctx context.Context) {
name := ctx.Session().Get("name")
if name == "" {
ctx.Writef("Empty name!!")
return
}
ctx.Writef("Hello %s", name)
ctx.Session().Delete("name")
})
app.Get("/test", func(ctx context.Context) {
name := ctx.Session().Get("name")
if name == "" {
ctx.Writef("Empty name!!")
return
}
ctx.Writef("Ok you are comming from /set ,the value of the name is %s", name)
ctx.Writef(", and again from the same context: %s", name)
ctx.Session().Delete("name")
})
app.Run(siris.Addr(":8080"))
}