Merge commit 'f6ba4ef440dcdedd2b46b0504efddb3c2676a39f' into ja
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# 6.3 Session storage
|
||||
|
||||
We introduced session manager work principle in previous section, we defined a session storage interface. In this section, I'm going to show you an example of memory-based session storage engine that implements the interface. You can change this to others forms of session storage as well.
|
||||
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.
|
||||
|
||||
package memory
|
||||
|
||||
@@ -115,14 +115,14 @@ We introduced session manager work principle in previous section, we defined a s
|
||||
}
|
||||
|
||||
|
||||
The above example implemented a memory-based session storage mechanism, then use init() function to register this storage engine to session manager. So how to register this engine?
|
||||
The above example implemented a memory based session storage mechanism. It uses its `init()` function to register this storage engine to the session manager. So how to register this engine from our main program?
|
||||
|
||||
import (
|
||||
"github.com/astaxie/session"
|
||||
_ "github.com/astaxie/session/providers/memory"
|
||||
)
|
||||
|
||||
Use import mechanism to register this engine in init() function automatically to session manager, then we use following code to initialize a session manager:
|
||||
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:
|
||||
|
||||
var globalSessions *session.Manager
|
||||
|
||||
@@ -135,5 +135,5 @@ Use import mechanism to register this engine in init() function automatically to
|
||||
## Links
|
||||
|
||||
- [Directory](preface.md)
|
||||
- Previous section: [How to use session in Go](06.2.md)
|
||||
- Previous section: [How to use sessions in Go](06.2.md)
|
||||
- Next section: [Prevent hijack of session](06.4.md)
|
||||
|
||||
Reference in New Issue
Block a user