Documentation ¶
Index ¶
Constants ¶
const ExpiredMember = "ijkbytes/memstore$expired"
To be compatible with Save(), define ExpiredMember as a special key for session expiration in server end.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GcOptions ¶
type GcOptions struct {
ScanLimit uint
}
GcOptions control the sessions's garbage collection. ScanLimit determines the number of sessions will be scan in random order while GC. Note: GC executes every 30 seconds; Get() will check if the session has expired.
type MemStore ¶
type MemStore struct { Codecs []securecookie.Codec Options *sessions.Options // contains filtered or unexported fields }
MemStore is an in-memory implementation of gorilla/sessions, suitable for use in tests and development environments. Do not use in production. Values are cached in a map. The cache is protected and can be used by multiple goroutines.
func NewMemStore ¶
NewMemStore returns a new MemStore. gcOpts control the sessions's garbage collection, see struct definition for more detail.
Keys are defined in pairs to allow key rotation, but the common case is to set a single authentication key and optionally an encryption key.
The first key in a pair is used for authentication and the second for encryption. The encryption key can be set to nil or omitted in the last pair, but the authentication key is required in all pairs.
It is recommended to use an authentication key with 32 or 64 bytes. The encryption key, if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.
Use the convenience function securecookie.GenerateRandomKey() to create strong keys.
func (*MemStore) Get ¶
Get returns a session for the given name after adding it to the registry.
It returns a new session if the sessions doesn't exist (if the session has expired in server end, return a new too). Access IsNew on the session to check if it is an existing session or a new one.
It returns a new session and an error if the session exists but could not be decoded.
func (*MemStore) MaxAge ¶
MaxAge sets the maximum age for the store and the underlying cookie implementation. Individual sessions can be deleted by setting Options.MaxAge = -1 for that session.
func (*MemStore) New ¶
New returns a session for the given name without adding it to the registry. It will if the session has expired in server end.
The difference between New() and Get() is that calling New() twice will decode the session data twice, while Get() registers and reuses the same decoded session after the first call.