forked from revel/revel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_engine.go
35 lines (30 loc) · 1.02 KB
/
session_engine.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
package revel
// The session engine provides an interface to allow for storage of session data
type (
SessionEngine interface {
Decode(c *Controller) // Called to decode the session information on the controller
Encode(c *Controller) // Called to encode the session information on the controller
}
)
var (
sessionEngineMap = map[string]func() SessionEngine{}
CurrentSessionEngine SessionEngine
)
// Initialize session engine on startup
func init() {
OnAppStart(initSessionEngine, 5)
}
func RegisterSessionEngine(f func() SessionEngine, name string) {
sessionEngineMap[name] = f
}
// Called when application is starting up
func initSessionEngine() {
// Check for session engine to use and assign it
sename := Config.StringDefault("session.engine", "revel-cookie")
if se, found := sessionEngineMap[sename]; found {
CurrentSessionEngine = se()
} else {
sessionLog.Warn("Session engine '%s' not found, using default session engine revel-cookie", sename)
CurrentSessionEngine = sessionEngineMap["revel-cookie"]()
}
}