Add API Framework Revel Source Files
[iec.git] / src / foundation / api / revel / session_engine.go
1 package revel
2
3 // The session engine provides an interface to allow for storage of session data
4 type (
5         SessionEngine interface {
6                 Decode(c *Controller) // Called to decode the session information on the controller
7                 Encode(c *Controller) // Called to encode the session information on the controller
8         }
9 )
10
11 var (
12         sessionEngineMap     = map[string]func() SessionEngine{}
13         CurrentSessionEngine SessionEngine
14 )
15
16 // Initialize session engine on startup
17 func init() {
18         OnAppStart(initSessionEngine, 5)
19 }
20
21 func RegisterSessionEngine(f func() SessionEngine, name string) {
22         sessionEngineMap[name] = f
23 }
24
25 // Called when application is starting up
26 func initSessionEngine() {
27         // Check for session engine to use and assign it
28         sename := Config.StringDefault("session.engine", "revel-cookie")
29         if se, found := sessionEngineMap[sename]; found {
30                 CurrentSessionEngine = se()
31         } else {
32                 sessionLog.Warn("Session engine '%s' not found, using default session engine revel-cookie", sename)
33                 CurrentSessionEngine = sessionEngineMap["revel-cookie"]()
34         }
35 }