Add en/0.6.x.md syntax highlighting
This commit is contained in:
12
en/06.3.md
12
en/06.3.md
@@ -1,7 +1,7 @@
|
||||
# 6.3 Session storage
|
||||
|
||||
We introduced a simple session manager's working principles in the previous section, and among other things, we defined a session storage interface. In this section, I'm going to show you an example of a memory based session storage engine that implements this interface. You can tailor this to other forms of session storage as well.
|
||||
|
||||
```Go
|
||||
package memory
|
||||
|
||||
import (
|
||||
@@ -114,16 +114,16 @@ We introduced a simple session manager's working principles in the previous sect
|
||||
session.Register("memory", pder)
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
The above example implements a memory based session storage mechanism. It uses its `init()` function to register this storage engine to the session manager. So how do we register this engine from our main program?
|
||||
|
||||
```Go
|
||||
import (
|
||||
"github.com/astaxie/session"
|
||||
_ "github.com/astaxie/session/providers/memory"
|
||||
)
|
||||
|
||||
```
|
||||
We use the blank import mechanism (which will invoke the package's `init()` function automatically) to register this engine to a session manager. We then use the following code to initialize the session manager:
|
||||
|
||||
```Go
|
||||
var globalSessions *session.Manager
|
||||
|
||||
// initialize in init() function
|
||||
@@ -131,7 +131,7 @@ We use the blank import mechanism (which will invoke the package's `init()` func
|
||||
globalSessions, _ = session.NewManager("memory", "gosessionid", 3600)
|
||||
go globalSessions.GC()
|
||||
}
|
||||
|
||||
```
|
||||
## Links
|
||||
|
||||
- [Directory](preface.md)
|
||||
|
||||
Reference in New Issue
Block a user