Documentation ¶
Overview ¶
Package session provides session storage facilities.
Index ¶
- func AddFlash(req *http.Request, flash Flash)
- func Bool(req *http.Request, k string, def bool) bool
- func Bump(req *http.Request)
- func Bytes(req *http.Request, k string, def []byte) []byte
- func Delete(req *http.Request, k string)
- func Get(req *http.Request, k string) (interface{}, bool)
- func Int(req *http.Request, k string, def int) int
- func Save(req *http.Request)
- func Set(req *http.Request, k string, v interface{}) error
- func String(req *http.Request, k string, def string) string
- type Config
- type Flash
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Gets a boolean value from the session for the given request under the given key. If the value is not present in the session, or it is not a boolean value, returns def.
func Bump ¶
Bump the epoch of the session, changing the cookie that the user agent must present and sending the new cookie to the user agent in the response.
func Bytes ¶
Gets a []byte value from the session for the given request under the given key. If the value is not present in the session, or it is not of type []byte, returns def.
func Get ¶
Get a value under the given key for the session for the given request.
The second parameter indicates whether the key exists.
func Int ¶
Gets an int value from the session for the given request under the given key. If the value is not present in the session, or it is not an int value, returns def.
func Save ¶
Save the session for the given request. No-op if the session has not been modified since load or since last calling this. Since this is called by InitHandler, you shouldn't need to call this yourself.
Types ¶
type Config ¶
type Config struct { // The session store to use. Required. Store storage.Store // The name to be used for the session cookie. Defaults to configurable // "sessioncookiename", which itself defaults to "s". CookieName string // Secret key used to generate the HMAC signatures for session cookies. // // If not specified, a temporary random key will be generated automatically. SecretKey []byte }
Session system configuration.
func (*Config) InitHandler ¶
Returns an HTTP handler which initializes the session information for the request and passes processing to the given handler. Also ensures that the session is saved, including in the event of a panic. Session saving is best effort and errors are not noted.
Sessions are loaded lazily; they are not loaded until information is actually requested from the session.
type Flash ¶
type Flash struct { // Should be one of "success", "error", "warning", "info" Severity string // Message to display. // May contain inline HTML, but should not contain block-level elements. Msg string }
A message which is returned once from the session store and then erased automatically.
Directories ¶
Path | Synopsis |
---|---|
Session storage, for use with session-pinning webservers only.
|
Session storage, for use with session-pinning webservers only. |
memorysession
Package memorysession provides an in-memory session store.
|
Package memorysession provides an in-memory session store. |
redissession
Package redissession provides a Redis-based session store.
|
Package redissession provides a Redis-based session store. |