forked from gin-contrib/sessions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
30 lines (27 loc) · 622 Bytes
/
main.go
File metadata and controls
30 lines (27 loc) · 622 Bytes
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
package main
import (
sessions "github.com/geschke/gin-contrib-sessions"
"github.com/geschke/gin-contrib-sessions/filesystem"
"github.com/gin-gonic/gin"
)
func main() {
sessionPath := "/tmp/"
r := gin.Default()
store := filesystem.NewStore(sessionPath, []byte("secret"))
r.Use(sessions.Sessions("mysession", store))
r.GET("/incr", func(c *gin.Context) {
session := sessions.Default(c)
var count int
v := session.Get("count")
if v == nil {
count = 0
} else {
count = v.(int)
count++
}
session.Set("count", count)
session.Save()
c.JSON(200, gin.H{"count": count})
})
r.Run(":8000")
}