File: session_engine.go

package info (click to toggle)
golang-github-revel-revel 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,240 kB
  • sloc: xml: 7; makefile: 7; javascript: 1
file content (35 lines) | stat: -rw-r--r-- 1,042 bytes parent folder | download | duplicates (2)
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"]()
	}
}