Documentation ¶
Index ¶
- Constants
- func New(name string, store SessionsStore, logger glog.ILogger) gin.HandlerFunc
- type CacheStore
- func (s *CacheStore) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
- func (s *CacheStore) Get(r *http.Request, name string) (*sessions.Session, error)
- func (s *CacheStore) New(r *http.Request, name string) (*sessions.Session, error)
- func (s *CacheStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
- func (s *CacheStore) SetKeyPrefix(p string)
- func (s *CacheStore) SetMaxAge(v int)
- func (s *CacheStore) SetMaxLength(l int)
- func (s *CacheStore) SetSerializer(ss SessionSerializer)
- type CookieStore
- type GobSerializer
- type ICacheStore
- type JSONSerializer
- type Options
- type Session
- type SessionSerializer
- type SessionsStore
Constants ¶
const (
DefaultKey = "github.com/gin-gonic/contrib/session"
)
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(name string, store SessionsStore, logger glog.ILogger) gin.HandlerFunc
Types ¶
type CacheStore ¶
type CacheStore struct { Cache cache.ICache Codecs []securecookie.Codec Options *sessions.Options // default configuration DefaultMaxAge int // default Redis TTL for a MaxAge == 0 session // contains filtered or unexported fields }
CacheStore stores session in a redis backend.
func NewCacheStore ¶
func NewCacheStore(cache cache.ICache, keyPairs ...[]byte) *CacheStore
NewCacheStore instantiates a CacheStore with a cache passed in.
func (*CacheStore) Delete ¶
func (s *CacheStore) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
Delete removes the session from redis, and sets the cookie to expire.
WARNING: This method should be considered deprecated since it is not exposed via the gorilla/session interface. Set session.Options.MaxAge = -1 and call Save instead. - July 18th, 2013
func (*CacheStore) Get ¶
Get returns a session for the given name after adding it to the registry.
See gorilla/session FilesystemStore.Get().
func (*CacheStore) New ¶
New returns a session for the given name without adding it to the registry.
See gorilla/session FilesystemStore.New().
func (*CacheStore) Save ¶
func (s *CacheStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
Save adds a single session to the response.
func (*CacheStore) SetKeyPrefix ¶
func (s *CacheStore) SetKeyPrefix(p string)
SetKeyPrefix set the prefix
func (*CacheStore) SetMaxAge ¶
func (s *CacheStore) SetMaxAge(v 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 (*CacheStore) SetMaxLength ¶
func (s *CacheStore) SetMaxLength(l int)
SetMaxLength sets CacheStore.maxLength if the `l` argument is greater or equal 0 maxLength restricts the maximum length of new session to l. If l is 0 there is no limit to the size of a session, use with caution. The default for a new CacheStore is 4096. Redis allows for max. Default: 4096,
func (*CacheStore) SetSerializer ¶
func (s *CacheStore) SetSerializer(ss SessionSerializer)
SetSerializer sets the serializer
type CookieStore ¶
type CookieStore interface { SessionsStore }
func NewCookieStore ¶
func NewCookieStore(keyPairs ...[]byte) CookieStore
NewCookieStore 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.
type GobSerializer ¶
type GobSerializer struct{}
GobSerializer uses gob package to encode the session map
func (GobSerializer) Deserialize ¶
func (s GobSerializer) Deserialize(d []byte, ss *sessions.Session) error
Deserialize back to map[interface{}]interface{}
type ICacheStore ¶
type ICacheStore interface { SessionsStore }
func NewStore ¶
func NewStore(cache cache.ICache, keyPairs ...[]byte) (ICacheStore, error)
NewStore size: maximum number of idle connections. network: tcp or udp address: host:port password: redis-password 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.
type JSONSerializer ¶
type JSONSerializer struct{}
JSONSerializer encode the session map to JSON.
func (JSONSerializer) Deserialize ¶
func (s JSONSerializer) Deserialize(d []byte, ss *sessions.Session) 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 Session ¶
type Session interface { // Get returns the session value associated to the given key. Get(key interface{}) interface{} // Set sets the session value associated to the given key. Set(key interface{}, val interface{}) // Delete removes the session value associated to the given key. Delete(key interface{}) // Clear deletes all values in the session. Clear() // AddFlash adds a flash message to the session. // A single variadic argument is accepted, and it is optional: it defines the flash key. // If not defined "_flash" is used by default. AddFlash(value interface{}, vars ...string) // Flashes returns a slice of flash messages from the session. // A single variadic argument is accepted, and it is optional: it defines the flash key. // If not defined "_flash" is used by default. Flashes(vars ...string) []interface{} // Options sets configuration for a session. Options(Options) // Save saves all session used during the current request. Save() error }
Session Wraps thinly gorilla-session methods. Session stores the values and optional configuration for a session.
type SessionSerializer ¶
type SessionSerializer interface { Deserialize(d []byte, ss *sessions.Session) error Serialize(ss *sessions.Session) ([]byte, error) }
SessionSerializer provides an interface hook for alternative serializers