session

package
v0.0.0-...-8fa2440 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package session provides session storage facilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFlash

func AddFlash(req *http.Request, flash Flash)

Add a flash message to the session for the given request.

func Bool

func Bool(req *http.Request, k string, def bool) 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

func Bump(req *http.Request)

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

func Bytes(req *http.Request, k string, def []byte) []byte

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 Delete

func Delete(req *http.Request, k string)

Delete the given key for the session for the given request, if it exists.

func Get

func Get(req *http.Request, k string) (interface{}, bool)

Get a value under the given key for the session for the given request.

The second parameter indicates whether the key exists.

func Int

func Int(req *http.Request, k string, def int) 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

func Save(req *http.Request)

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.

func Set

func Set(req *http.Request, k string, v interface{}) error

Set a value under the given key for the session for the given request.

func String

func String(req *http.Request, k string, def string) string

Gets a string 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 string value, returns def.

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

func (cfg *Config) InitHandler(h http.Handler) http.Handler

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.

func GetFlash

func GetFlash(req *http.Request) []Flash

Retrieve the list of flash messages for the session for the given request. The messages are deleted from the session automatically, so future calls to this function will return an empty slice.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL