Documentation ¶
Index ¶
- Variables
- func Middleware(name string, store Store) mel.Handler
- func Session(c *mel.Context) *session
- type Contents
- type CookieStore
- type GobSerializer
- type JSONSerializer
- type Options
- type RedisStore
- func NewRedisStore(size int, network, address, password string, keyPairs ...[]byte) (*RedisStore, error)
- func NewRedisStoreWithDB(size int, network, address, password, DB string, keyPairs ...[]byte) (*RedisStore, error)
- func NewRedisStoreWithPool(pool *redis.Pool, keyPairs ...[]byte) (*RedisStore, error)
- func (s *RedisStore) Close() error
- func (store *RedisStore) Get(r *http.Request, name string, s *session) error
- func (store *RedisStore) Save(r *http.Request, w http.ResponseWriter, s *session) error
- func (store *RedisStore) SetKeyPrefix(p string)
- func (store *RedisStore) SetMaxAge(age int)
- func (store *RedisStore) SetMaxLength(l int)
- func (store *RedisStore) SetSerializer(ss SessionSerializer)
- type SessionSerializer
- type Store
Constants ¶
This section is empty.
Variables ¶
var ContextKey = "SESSION"
Key for session storing into context. You can change it, i.e., session.ContextKey = "XXX".
Functions ¶
func Middleware ¶
Middleware returns a middleware that handles session.
Types ¶
type CookieStore ¶
type CookieStore struct { Codecs []securecookie.Codec *Options // default configuration }
CookieStore stores sessions using secure cookies.
func NewCookieStore ¶
func NewCookieStore(keyPairs ...[]byte) *CookieStore
NewCookieStore returns a new CookieStore.
Keys are defined in pairs to allow key rotation, but the common case is to set a single authentication key and optionally an encryption key.
The first key in a pair is used for authentication and the second for encryption. The encryption key can be set to nil or omitted in the last pair, but the authentication key is required in all pairs.
It is recommended to use an authentication key with 32 or 64 bytes. The encryption key, if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.
Use the convenience function securecookie.GenerateRandomKey() to create strong keys.
func (*CookieStore) Get ¶
func (store *CookieStore) Get(r *http.Request, name string, s *session) error
Get returns a session for the given name.
It returns a new session if the sessions doesn't exist. Access IsNew on the session to check if it is an existing session or a new one.
It returns a new session and an error if the session exists but could not be decoded.
func (*CookieStore) MaxAge ¶
func (store *CookieStore) MaxAge(age int)
MaxAge sets the maximum age for cookie. Individual sessions can be deleted by setting Options.MaxAge = -1 for that session.
func (*CookieStore) Save ¶
func (store *CookieStore) Save(r *http.Request, w http.ResponseWriter, s *session) error
Save adds a single session to the response.
type GobSerializer ¶
type GobSerializer struct{}
GobSerializer uses gob package to encode the session map
func (GobSerializer) Deserialize ¶
func (s GobSerializer) Deserialize(d []byte, sv *Contents) error
Deserialize back to map[interface{}]interface{}
type JSONSerializer ¶
type JSONSerializer struct{}
JSONSerializer encode the session map to JSON.
func (JSONSerializer) Deserialize ¶
func (s JSONSerializer) Deserialize(d []byte, sv *Contents) error
Deserialize back to map[string]interface{}
type Options ¶
type Options struct { Path string Domain string // MaxAge=0 means no 'Max-Age' attribute specified. // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'. // MaxAge>0 means Max-Age attribute present and given in seconds. MaxAge int Secure bool HttpOnly bool }
Options stores configuration for a session or session store. Fields are a subset of http.Cookie fields.
type RedisStore ¶
type RedisStore struct { Pool *redis.Pool Codecs []securecookie.Codec *Options // default configuration DefaultMaxAge int // default Redis TTL for a MaxAge == 0 session // contains filtered or unexported fields }
func NewRedisStore ¶
func NewRedisStore(size int, network, address, password string, keyPairs ...[]byte) (*RedisStore, error)
NewRedisStore returns a new RedisStore. size: maximum number of idle connections.
func NewRedisStoreWithDB ¶
func NewRedisStoreWithDB(size int, network, address, password, DB string, keyPairs ...[]byte) (*RedisStore, error)
NewRedisStoreWithDB - like NewRedisStore but accepts `DB` parameter to select redis DB instead of using the default one ("0")
func NewRedisStoreWithPool ¶
func NewRedisStoreWithPool(pool *redis.Pool, keyPairs ...[]byte) (*RedisStore, error)
NewRedisStoreWithPool instantiates a RedisStore with a *redis.Pool passed in.
func (*RedisStore) Close ¶
func (s *RedisStore) Close() error
Close closes the underlying *redis.Pool
func (*RedisStore) Get ¶
func (store *RedisStore) Get(r *http.Request, name string, s *session) error
func (*RedisStore) Save ¶
func (store *RedisStore) Save(r *http.Request, w http.ResponseWriter, s *session) error
func (*RedisStore) SetKeyPrefix ¶
func (store *RedisStore) SetKeyPrefix(p string)
SetKeyPrefix set the prefix
func (*RedisStore) SetMaxAge ¶
func (store *RedisStore) SetMaxAge(age int)
SetMaxAge restricts the maximum age, in seconds, of the session record both in database and a browser. This is to change session storage configuration. If you want just to remove session use your session `s` object and change it's `Options.MaxAge` to -1, as specified in
http://godoc.org/github.com/gorilla/sessions#Options
Default is the one provided by this package value - `sessionExpire`. Set it to 0 for no restriction. Because we use `MaxAge` also in SecureCookie crypting algorithm you should use this function to change `MaxAge` value.
func (*RedisStore) SetMaxLength ¶
func (store *RedisStore) SetMaxLength(l int)
SetMaxLength sets RedisStore.maxLength if the `l` argument is greater or equal 0 maxLength restricts the maximum length of new sessions to l. If l is 0 there is no limit to the size of a session, use with caution. The default for a new RedisStore is 4096. Redis allows for max. value sizes of up to 512MB (http://redis.io/topics/data-types) Default: 4096,
func (*RedisStore) SetSerializer ¶
func (store *RedisStore) SetSerializer(ss SessionSerializer)
SetSerializer sets the serializer