forked from gobuffalo/suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
38 lines (31 loc) · 809 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
package suite
import (
"net/http"
"github.com/gorilla/sessions"
)
type sessionStore struct {
sessions map[string]*sessions.Session
}
func newSessionStore() sessions.Store {
return &sessionStore{
sessions: map[string]*sessions.Session{},
}
}
func (s *sessionStore) Get(r *http.Request, name string) (*sessions.Session, error) {
if s, ok := s.sessions[name]; ok {
return s, nil
}
return s.New(r, name)
}
func (s *sessionStore) New(r *http.Request, name string) (*sessions.Session, error) {
sess := sessions.NewSession(s, name)
s.sessions[name] = sess
return sess, nil
}
func (s *sessionStore) Save(r *http.Request, w http.ResponseWriter, sess *sessions.Session) error {
if s.sessions == nil {
s.sessions = map[string]*sessions.Session{}
}
s.sessions[sess.Name()] = sess
return nil
}