sessions

package
v0.0.0-...-cbc4e0b Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2014 License: AGPL-3.0, BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package gorilla/appengine/sessions implements session stores for Google App Engine's datastore and memcache.

Usage is the same as described in gorilla/sessions documentation:

http://gorilla-web.appspot.com/pkg/gorilla/sessions

...but you'll use the DatastoreStore or MemcacheStore to load and save your sessions. Let's initialize both:

var dStore = sessions.NewDatastoreStore("", []byte("very-secret"))
var mStore = sessions.NewMemcacheStore("", []byte("a-lot-secret"))

After this, call the appropriate store to retrieve a session, and then call Save() on the session to save it:

func MyHandler(w http.ResponseWriter, r *http.Request) {
	// Get a session. We're ignoring the error resulted from decoding an
	// existing session: Get() always returns a session, even if empty.
	session, _ := dStore.Get(r, "session-name")
	// Set some session values.
	session.Values["foo"] = "bar"
	session.Values[42] = 43
	// Save it.
	session.Save(r, w)
}

Check the sessions package documentation for more details about other features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatastoreStore

type DatastoreStore struct {
	Codecs  []securecookie.Codec
	Options *sessions.Options // default configuration
	// contains filtered or unexported fields
}

DatastoreStore stores sessions in the App Engine datastore.

func NewDatastoreStore

func NewDatastoreStore(kind string, keyPairs ...[]byte) *DatastoreStore

NewDatastoreStore returns a new DatastoreStore.

The kind argument is the kind name used to store the session data. If empty it will use "Session".

See NewCookieStore() for a description of the other parameters.

func (*DatastoreStore) Get

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

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

See CookieStore.Get().

func (*DatastoreStore) New

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

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

See CookieStore.New().

func (*DatastoreStore) Save

Save adds a single session to the response.

type MemcacheStore

type MemcacheStore struct {
	Codecs  []securecookie.Codec
	Options *sessions.Options // default configuration
	// contains filtered or unexported fields
}

MemcacheStore stores sessions in the App Engine memcache.

func NewMemcacheStore

func NewMemcacheStore(keyPrefix string, keyPairs ...[]byte) *MemcacheStore

NewMemcacheStore returns a new MemcacheStore.

The keyPrefix argument is the prefix used for memcache keys. If empty it will use "gorilla.appengine.sessions.".

See NewCookieStore() for a description of the other parameters.

func (*MemcacheStore) Get

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

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

See CookieStore.Get().

func (*MemcacheStore) New

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

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

See CookieStore.New().

func (*MemcacheStore) Save

Save adds a single session to the response.

type Session

type Session struct {
	Date  time.Time
	Value []byte
}

Session is used to load and save session data in the datastore.

Jump to

Keyboard shortcuts

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