Documentation ¶
Index ¶
- type Client
- type GobSerializer
- type JSONSerializer
- type KeyGenFunc
- type Options
- type SessionSerializer
- type Store
- func (s *Store) Get(r *http.Request, name string) (*sessions.Session, error)
- func (s *Store) New(r *http.Request, name string) (*sessions.Session, error)
- func (s *Store) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
- func (s *Store) SetMaxAge(age int)
- func (s *Store) SetOptions(options sessions.Options)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v1.1.0
type Client interface { // Get returns the value for a given key. Get(ctx context.Context, key string) ([]byte, error) // Set sets the value for a given key. Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error // Del deletes a given key. Del(ctx context.Context, key string) error }
type GobSerializer ¶
type GobSerializer struct{}
GobSerializer uses the 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 JSONSerializer ¶
type JSONSerializer struct{}
JSONSerializer encodes 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 KeyGenFunc ¶
type KeyGenFunc func() string
KeyGenFunc defines a function used by store to generate the session key.
type Options ¶
type Options func(s *Store)
func WithKeyGenerator ¶
func WithKeyGenerator(keyGen KeyGenFunc) Options
WithKeyGenerator sets the key generator used to generate the session key. By default, the defaultKeyGenerator method is used.
func WithKeyPrefix ¶
WithKeyPrefix sets the key prefix used in redis keys.
func WithSerializer ¶
func WithSerializer(serializer SessionSerializer) Options
WithSerializer sets the serializer used to serialize the session. By default, the GobSerializer is used.
func WithSessionOptions ¶
WithSessionOptions sets the session options.
type SessionSerializer ¶
type SessionSerializer interface { Deserialize(d []byte, ss *sessions.Session) error Serialize(ss *sessions.Session) ([]byte, error) }
SessionSerializer provides an interface for alternative serializers.
type Store ¶
type Store struct { Options *sessions.Options Codecs []securecookie.Codec // contains filtered or unexported fields }
func (*Store) Get ¶
Get returns a session for the given name after adding it to the registry.
ref: https://github.com/gorilla/sessions/blob/0e1d1d7c382124033b710ef1ef0993327195ed40/store.go#L178
func (*Store) New ¶
New returns a session for the given name without adding it to the registry.
ref: https://github.com/gorilla/sessions/blob/0e1d1d7c382124033b710ef1ef0993327195ed40/store.go#L185
func (*Store) Save ¶
Save adds a single session to the response.
If the Options.MaxAge of the session is <= 0, the session is deleted.
func (*Store) SetMaxAge ¶ added in v1.0.2
SetMaxAge sets the maximum age for the store and the underlying cookie implementation. Individual sessions can be deleted by setting Options.MaxAge = -1 for that session.
ref: https://github.com/gorilla/sessions/blob/0e1d1d7c382124033b710ef1ef0993327195ed40/store.go#L243
func (*Store) SetOptions ¶ added in v1.0.2
SetOptions sets the options for the store.