-
Notifications
You must be signed in to change notification settings - Fork 1
/
session.go
28 lines (26 loc) · 954 Bytes
/
session.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
package config
import (
"github.com/bradfitz/gomemcache/memcache"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"os"
)
func InitializeSession() gin.HandlerFunc {
sessionDriver := os.Getenv("SESSION_STORE_DRIVER")
sessionName := os.Getenv("SESSION_STORE_NAME")
appKey := os.Getenv("APP_KEY")
switch sessionDriver {
case "cookie":
store := sessions.NewCookieStore([]byte(appKey))
return sessions.Sessions(sessionName, store)
case "redis":
store, _ := sessions.NewRedisStore(10, "tcp", os.Getenv("SESSION_HOST") + ":" + os.Getenv("SESSION_PORT"), "", []byte(appKey))
return sessions.Sessions(sessionName, store)
case "memcache":
store := sessions.NewMemcacheStore(memcache.New(os.Getenv("SESSION_HOST") + ":" + os.Getenv("SESSION_PORT")), "", []byte(appKey))
return sessions.Sessions(sessionName, store)
default:
store := sessions.NewCookieStore([]byte(appKey))
return sessions.Sessions(sessionName, store)
}
}