Documentation ¶
Overview ¶
Package ramstore implements an in-memory session store for Gorilla Web Toolkit. In-memory sessions expire after a set time of inactivity.
Index ¶
- type RAMSessions
- func (r *RAMSessions) AsPoller() SessionData
- func (r *RAMSessions) Get(id string) map[interface{}]interface{}
- func (r *RAMSessions) GetData(id string) (map[interface{}]interface{}, error)
- func (r *RAMSessions) Poll(id string) map[interface{}]interface{}
- func (r *RAMSessions) Purge()
- func (r *RAMSessions) Save(id string, data map[interface{}]interface{})
- func (r *RAMSessions) SaveData(id string, data map[interface{}]interface{}) error
- type RAMStore
- type SessionData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RAMSessions ¶
type RAMSessions struct {
// contains filtered or unexported fields
}
RAMSessions stores session data. Session data for a particular session expires after a set time of inactivity for that session. RAMSessions can be safely used with multiple goroutines. Clients should not use this type directly, but should use RAMStore instead.
func NewRAMSessions ¶
func NewRAMSessions(maxAge int) *RAMSessions
NewRAMSessions creates a new RAMSessions instance. maxAge is the maximum allowed inactivity in seconds before data for a particular session expires.
func (*RAMSessions) AsPoller ¶
func (r *RAMSessions) AsPoller() SessionData
AsPoller returns a view of this instance that does not keep session data from expiring when it is fetched.
func (*RAMSessions) Get ¶
func (r *RAMSessions) Get(id string) map[interface{}]interface{}
Get returns a shallow copy of the session data for a particular session ID. Get returns nil if the session ID does not exist or if the session data for the session ID expired from too much inactivity.
func (*RAMSessions) GetData ¶
func (r *RAMSessions) GetData(id string) (map[interface{}]interface{}, error)
GetData returns Get(id), nil
func (*RAMSessions) Poll ¶
func (r *RAMSessions) Poll(id string) map[interface{}]interface{}
Poll works just like Get except that calling Poll does not keep session data from expiring.
func (*RAMSessions) Purge ¶
func (r *RAMSessions) Purge()
Purge removes session data that has already expired. Clients need not call this manually as a separate go routine calls this periodically.
func (*RAMSessions) Save ¶
func (r *RAMSessions) Save(id string, data map[interface{}]interface{})
Save saves new session data for a particular session ID. Save makes a shallow copy of data before saving it.
func (*RAMSessions) SaveData ¶
func (r *RAMSessions) SaveData( id string, data map[interface{}]interface{}) error
SaveData calls Save(id, data) and returns nil.
type RAMStore ¶
type RAMStore struct { Options *sessions.Options Data *RAMSessions // Client sets either Data or SData leaving the other nil. If both Data and // SData are non-nil then SData takes precedence. SData SessionData }
RAMStore is an in-memory session store for Gorilla Web Toolkit. This store makes shallow copies of maps, so value objects such as string and int can be safely used with in-memory sessions with no regard for synchronization. Care must be taken with reference types such as pointers, maps, or slices. To what these reference refer must be treated as frozen to prevent contention with other go-routines.
func NewRAMStore ¶
NewRAMStore creates a new in-memory session store. maxAge is the maximum time of inactivity in seconds before a session expires. NewRamStore is a convenience routine that returns a *RamStore with the Data field set and the SData field nil. The returned *RamStore uses '/' as the cookie path.
func (*RAMStore) Get ¶
Get retrieves the session. name is the name of the cookie storing the session ID. If Get is called a second time with the same request pointer, the session is retrieved from the request's context rather than from this store. Callers should call context.Clear() in a defer statement after calling Get.
func (*RAMStore) New ¶
New fetches the session from this store. name is the name of the cookie holding the session ID. Get calls New if the session is not already cached in the request's context. This implementation of New never returns a non-nil error if client is storing sessions data in a *RamSessions instance.
type SessionData ¶
type SessionData interface { // GetData gets session data by id. GetData must return a shallow copy of // the data. GetData(id string) (map[interface{}]interface{}, error) // SaveData saves session data by id. SaveData must make a shallow copy of // values before saving. SaveData(id string, values map[interface{}]interface{}) error }
Clients may choose to write their own implementation of the SessionData interface instead of using RAMSessions.