-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
47 lines (41 loc) · 935 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
35
36
37
38
39
40
41
42
43
44
45
46
47
package session
import (
// base core imports
"net/http"
// external imports
"github.com/gorilla/sessions"
)
// set cookie store variables
var (
// cookie store
Store *sessions.CookieStore
// session name
Name string
)
// Session struct
// Stores session options, name and secret key values
type Session struct {
Options sessions.Options `json:"Options"`
Name string `json:"Name"`
SecretKey string `json:"SecretKey"`
}
// Configure session
// Setting session values
func Configure(s Session) {
Store = sessions.NewCookieStore([]byte(s.SecretKey))
Store.Options = &s.Options
Name = s.Name
}
// Instance function
// spawn new session instance
func Instance(r *http.Request) *sessions.Session {
session, _ := Store.Get(r, Name)
return session
}
// Empty function
// delete all session values
func Empty(sess *sessions.Session) {
for s := range sess.Values {
delete(sess.Values, s)
}
}