Documentation
¶
Overview ¶
Package session provides an interface for managing user sessions. This file contains an implementation of the Store interface using an in-memory store.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateNewSessionID ¶
CreateNewSessionID generates a random session id. Also check for collisions so we don't accidentally assign an existing session id.
func TestStoreImplementation ¶
func TestStoreImplementation(t *testing.T, impl StoreImplementation)
TestStoreImplementation tests a session store implementation.
Types ¶
type Data ¶
type Data map[string]interface{}
Data is the stored session data.
type Store ¶
type Store interface {
// CreateSession creates a new session in the store. The expires parameter is the expire
// time in nanonseconds for the session. Returns the session ID.
CreateSession(expires int64) (string, error)
// GetSession returns the session from the session store based
// on given ID and where expire is higher than provided nanoseconds.
GetSession(sessionID string, ingnoreOlderNs int64) (Session, error)
// RemoveSession removes the session from the store.
RemoveSession(sessionID string) error
// GetSessions returns sessions with expire time is less than given time in nanoseconds.
GetSessions(time int64) ([]Session, error)
// RefreshSession refreshes a session expire time by adding the given nanoseconds.
RefreshSession(sessionID string, expireAddNs int64) error
// SetSessionData sets the session data in the store.
SetSessionData(sessionID string, data Data) error
// GetSessionData returns the session data from the store.
GetSessionData(sessionID string) (Data, error)
// RemoveSessionData removes the session data from the store.
RemoveSessionData(sessionID string) error
}
Store is the interface for the session back-end store.
func NewInMemoryStore ¶
func NewInMemoryStore() Store
NewInMemoryStore returns a new instance of inMemoryStore.
type StoreImplementation ¶
Click to show internal directories.
Click to hide internal directories.