-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
34 lines (28 loc) · 929 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
31
32
33
34
package session
import (
"net/http"
"github.com/gorilla/sessions"
)
var (
// Store is the cookie store
Store *sessions.CookieStore
// Name is the session name
Name string
)
// Session stores session level information
type Session struct {
Options sessions.Options `json:"Options"` // Pulled from: http://www.gorillatoolkit.org/pkg/sessions#Options
Name string `json:"Name"` // Name for: http://www.gorillatoolkit.org/pkg/sessions#CookieStore.Get
SecretKey string `json:"SecretKey"` // Key for: http://www.gorillatoolkit.org/pkg/sessions#CookieStore.New
}
// Configure the session cookie store
func Configure(s Session) {
Store = sessions.NewCookieStore([]byte(s.SecretKey))
Store.Options = &s.Options
Name = s.Name
}
// Session returns a new session, never returns an error
func Instance(r *http.Request) *sessions.Session {
session, _ := Store.Get(r, Name)
return session
}