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 ¶
Get returns a session for the given name after adding it to the registry.
See CookieStore.Get().
func (*DatastoreStore) New ¶
New returns a session for the given name without adding it to the registry.
See CookieStore.New().
func (*DatastoreStore) Save ¶
func (s *DatastoreStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
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 ¶
Get returns a session for the given name after adding it to the registry.
See CookieStore.Get().
func (*MemcacheStore) New ¶
New returns a session for the given name without adding it to the registry.
See CookieStore.New().
func (*MemcacheStore) Save ¶
func (s *MemcacheStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
Save adds a single session to the response.