package module
v0.0.0-...-11e8906 Latest Latest

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

Go to latest
Published: Feb 8, 2019 License: LGPL-3.0 Imports: 19 Imported by: 0



This is a fork of to support Firestore instead of Datastore.


  • don't use GAE's memcache package.




View Source
const (
	CkDoDisplayLogging            = "SessionCascadeDisplayLogging"
	CkMaxMemcacheSessionSizeBytes = "MaxMemcacheSessionSizeBytes"

Config keys

View Source
const (
	RequestBackend   = 1 << iota
	MemcacheBackend  = 1 << iota
	FirestoreBackend = 1 << iota
View Source
const (
	// In most cases we won't want to use the "request" backend. Though it's
	// nice to prevent hitting Memcache or Firestore if the information is
	// requested multiple times during a single request, it won't be updated by
	// concurrent requests from the same user/browser. The distributed backends
	// will receive the updates but the "Request" backend will preempt it with
	// potentially old information. We'd have to implement a secondary channel,
	// like the Channel API, to receive fault notifications from other requests
	// that do an update so that we can know to update the information in the
	// request.
	DistributedBackends = MemcacheBackend | FirestoreBackend
	AllBackends         = RequestBackend | MemcacheBackend | FirestoreBackend

	// Amount of time for cookies/redis keys to expire.
	DefaultExpireSeconds = 86400 * 30
	MaxValueLength       = 4096
	DefaultMaxAgeSeconds = 60 * 20
	DefaultKeyPrefix     = "session."


View Source
var (
	ErrValueTooBig = e.New("the value to store for the session is too big")



func SetupFirestore

func SetupFirestore(fsc *firestore.Client)


type CascadeStore

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

func NewCascadeStore

func NewCascadeStore(backendTypes int, keyPairs ...[]byte) *CascadeStore

func (*CascadeStore) Get

func (cs *CascadeStore) 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 (*CascadeStore) New

func (cs *CascadeStore) New(r *http.Request, name string) (session *sessions.Session, err error)

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

See gorilla/sessions FilesystemStore.New().

func (*CascadeStore) Save

func (cs *CascadeStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) (err error)

Save adds a single session to the response.

func (*CascadeStore) SetKeyPrefix

func (cs *CascadeStore) SetKeyPrefix(p string)

SetKeyPrefix set the prefix

func (*CascadeStore) SetMaxAge

func (cs *CascadeStore) 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

Default is the one provided by this package value - `DefaultExpireSeconds`. 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 (*CascadeStore) SetMaxLength

func (cs *CascadeStore) 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 ( Default: 4096,

func (*CascadeStore) SetSerializer

func (cs *CascadeStore) SetSerializer(ss SessionSerializer)

SetSerializer sets the serializer

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 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

Jump to

Keyboard shortcuts

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