-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
30 lines (26 loc) · 837 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
29
30
package middleware
import (
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"net/http"
)
func Session(conf *viper.Viper, store sessions.Store) gin.HandlerFunc {
return sessions.Sessions(conf.GetString("session.sessionId"), store)
}
func NewCookieStore(conf *viper.Viper) sessions.Store {
store := cookie.NewStore(
[]byte(conf.GetString("session.authentication")),
[]byte(conf.GetString("session.encryption")),
)
store.Options(sessions.Options{
Path: conf.GetString("cookie.Path"),
Domain: conf.GetString("cookie.Domain"),
MaxAge: conf.GetInt("cookie.MaxAge"),
Secure: conf.GetBool("cookie.Secure"),
HttpOnly: conf.GetBool("cookie.HttpOnly"),
SameSite: http.SameSite(conf.GetInt("cookie.SameSite")),
})
return store
}