Documentation ¶
Overview ¶
Package sessions provides HTTP(S) sessions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Filter ¶
type Filter struct { DateCreatedAfter time.Time DateCreatedBefore time.Time IDs []string UserIDs []string }
Filter is used to limit DeleteMulti and GetMulti to sessions that match the criteria. Sessions match when 1) they have an ID or userID that is specified in IDs or UserIDs, and 2) their DateCreated is before DateCreatedBefore or after DateCreatedAfter. If both IDs and UserIDs are empty, sessions match regardless of their ID and session ID. If both DateCreatedBefore and DateCreatedAfter are zero, sessions match regardless of their DateCreated. Thus, with no filter set, all sessions match.
type Flash ¶
type Flash interface { // HTMLUnsafe returns the message without escaping it. This is useful if // the message contains HTML code that should be rendered by the browser. HTMLUnsafe() template.HTML // Message returns the flash’s message. Message() string // SetMessage sets the flash’s message. SetMessage(string) // SetType sets the flash’s type. SetType(string) // String returns the flash’s message. String() string // Type returns the flash’s type. Type() string // Flash supports JSON encoding. json.Marshaler }
Flash consists of a message that should be displayed to the user, and a type that can be used to style the message appropriately.
func FlashesFromJSON ¶
FlashesFromJSON JSON decodes an array of Flash objects. The result is useful as input for Flashes.Add.
type Flashes ¶
type Flashes interface { // Add adds flashes. Add(flashes ...Flash) // AddNew creates a new Flash and adds it. flashType is optional. Only the // first given flashType is used. AddNew(message string, flashType ...string) Flash // GetAll returns all flashes. GetAll() []Flash // Remove removes flashes. Remove(flashes ...Flash) // RemoveAll removes all flashes. RemoveAll() }
Flashes manages flashes.
type Session ¶
type Session interface { // DateCreated returns the session’s creation date. DateCreated() time.Time // Delete deletes the session from the session store. Delete(http.ResponseWriter) error // Flashes returns the session’s flash container. Flashes() Flashes // ID returns the session’s ID. ID() string // IsStored returns true if the session exists in the store. IsStored() bool // Save saves the session to the session store. Save(http.ResponseWriter) error // SetDateCreated sets the session’s creation date. SetDateCreated(time.Time) // SetIsStored sets whether the session exists in the store. Only the store // should call this method. SetIsStored(bool) // Store returns the session store. Store() Store // Values returns the session’s value container. Values() Values }
Session represents an HTTP(S) session.
func NewSession ¶
NewSession returns a new session. The session has not been saved to the session store yet. To do that, call Save.
type Store ¶
type Store interface { // Delete deletes a session from the store, and deletes the session cookie. Delete(writer http.ResponseWriter, sessionID string) error // DeleteMulti deletes sessions from the store that match the criteria // specified in filter. DeleteMulti(filter *Filter) error // Get gets a session from the store using the session ID stored in the // session cookie. Get(http.ResponseWriter, *http.Request) (Session, error) // GetMulti gets sessions from the store that match the criteria specified // in filter. GetMulti(filter *Filter) ([]Session, error) // Save saves a session to the store and creates / updates the session // cookie. Save(http.ResponseWriter, Session) error // SaveMulti saves the provided sessions. SaveMulti([]Session) error }
Store represents a session store.
type Values ¶
type Values interface { // Get gets the value associated with key. If there is no value associated // with key, Get returns an empty string. Get(key string) string // GetAll returns all keys and their associated value. GetAll() map[string]string // Remove removes values associated with the provided keys. Remove(keys ...string) // RemoveAll removes all keys and values. RemoveAll() // Set sets the key to value. Set(key, value string) // SetAll sets all provided keys to their associated value. SetAll(map[string]string) }
Values contains keys and associated values.
Directories ¶
Path | Synopsis |
---|---|
Package sqlsessionstores provides a session store backed by an SQL database.
|
Package sqlsessionstores provides a session store backed by an SQL database. |