sessions

package
v1.0.59 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNonStringKey     = errors.New("non-string key value, cannot serialize session to JSON")
	ErrStoreValueTooBig = errors.New("the value to store is too big")
	ErrMarshal          = errors.New("error marshaling session")
	ErrUnmarshal        = errors.New("error unmarshaling session")
	ErrSerialization    = errors.New("error serializing session")
	ErrDeserialization  = errors.New("error deserializing session")
	ErrClose            = errors.New("error closing session")
	ErrGetSession       = errors.New("error getting session")
	ErrDeletingSession  = errors.New("error deleting session")
	ErrSavingSession    = errors.New("error saving session")
	ErrCookieEncode     = errors.New("error encoding cookie")
	ErrRedis            = errors.New("error with redis")
	ErrSetExpiration    = errors.New("error setting expiration")
)
View Source
var (
	ErrCast = errors.New("unable to cast Store to *store")
)

Functions

func SetKeyPrefix

func SetKeyPrefix(s Store, prefix string) error

SetKeyPrefix sets the key prefix in the redis database.

Types

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{}.

func (GobSerializer) Serialize

func (s GobSerializer) Serialize(ss *sessions.Session) ([]byte, error)

Serialize using gob.

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{}.

func (JSONSerializer) Serialize

func (s JSONSerializer) Serialize(ss *sessions.Session) ([]byte, error)

Serialize to JSON. Will err if there are unmarshalable key values.

type RediStore

type RediStore struct {
	DB            *redis.Client
	Codecs        []securecookie.Codec
	Options       *sessions.Options // default configuration
	DefaultMaxAge int               // default Redis TTL for a MaxAge == 0 session
	// contains filtered or unexported fields
}

RediStore stores sessions in a redis backend.

func GetRedisStore

func GetRedisStore(s Store) (*RediStore, error)

GetRedisStore get the actual woking store. Ref: https://godoc.org/github.com/boj/redistore#RediStore

func NewRediStore

func NewRediStore(db *redis.Client, keyPairs ...[]byte) (*RediStore, error)

NewRediStore instantiates a RediStore.

func (*RediStore) Close

func (s *RediStore) Close() error

Close closes the underlying *redis.Pool.

func (*RediStore) Delete

func (s *RediStore) 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/sessions interface. Set session.Options.MaxAge = -1 and call Save instead. - July 18th, 2013.

func (*RediStore) Get

func (s *RediStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get returns a session for the given name after adding it to the registry.

See gorilla/sessions FilesystemStore.Get().

func (*RediStore) New

func (s *RediStore) New(r *http.Request, name string) (*sessions.Session, error)

New returns a session for the given name without adding it to the registry.

See gorilla/sessions FilesystemStore.New().

func (*RediStore) Save

func (s *RediStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save adds a single session to the response.

func (*RediStore) SetKeyPrefix

func (s *RediStore) SetKeyPrefix(p string)

SetKeyPrefix set the prefix.

func (*RediStore) SetMaxAge

func (s *RediStore) 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 (*RediStore) SetMaxLength

func (s *RediStore) SetMaxLength(l int)

SetMaxLength sets RediStore.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 RediStore is 4096. Redis allows for max. value sizes of up to 512MB (http://redis.io/topics/data-types) Default: 4096.

func (*RediStore) SetSerializer

func (s *RediStore) SetSerializer(ss SessionSerializer)

SetSerializer sets the serializer.

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.

type Store

type Store interface {
	sessions.Store
}

func NewStore

func NewStore(db *redis.Client, keyPairs ...[]byte) (Store, error)

NewStore creates a new redis store.

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.

Jump to

Keyboard shortcuts

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