forked from go-session/session
/
default.go
39 lines (32 loc) · 868 Bytes
/
default.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
package session
import (
"context"
"net/http"
"sync"
)
var (
internalManager *Manager
once sync.Once
)
func manager(opt ...Option) *Manager {
once.Do(func() {
internalManager = NewManager(opt...)
})
return internalManager
}
// InitManager initialize the global session management instance
func InitManager(opt ...Option) {
manager(opt...)
}
// Start a session and return to session storage
func Start(ctx context.Context, w http.ResponseWriter, r *http.Request) (Store, error) {
return manager().Start(ctx, w, r)
}
// Destroy a session
func Destroy(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
return manager().Destroy(ctx, w, r)
}
// Refresh a session and return to session storage
func Refresh(ctx context.Context, w http.ResponseWriter, r *http.Request) (Store, error) {
return manager().Refresh(ctx, w, r)
}