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
...with a little preparation needed: the new stores must be registered and their secret keys must be set before use. We can do it in a init() function:
import ( // ... appengineSessions "gorilla.googlecode.com/hg/gorilla/appengine/sessions" "gorilla.googlecode.com/hg/gorilla/sessions" ) func init() { // Register the datastore and memcache session stores. sessions.SetStore("datastore", new(appengineSessions.DatastoreSessionStore)) sessions.SetStore("memcache", new(appengineSessions.MemcacheSessionStore)) // Set secret keys for the session stores. sessions.SetStoreKeys("datastore", []byte("my-secret-key")) sessions.SetStoreKeys("memcache", []byte("my-secret-key")) }
After this, to retrieve a session using datastore or memcache, pass a third parameter to sessions.Session() with the key used to register the store. For datastore:
if session, err := sessions.Session(r, "", "datastore"); err == nil { session["foo"] = "bar" sessions.Save(r, w) }
Or for memcache:
if session, err := sessions.Session(r, "", "memcache"); err == nil { session["foo"] = "bar" sessions.Save(r, w) }
Index ¶
- type DatastoreSessionStore
- func (s *DatastoreSessionStore) Encoders() []sessions.SessionEncoder
- func (s *DatastoreSessionStore) Load(r *http.Request, key string, info *sessions.SessionInfo)
- func (s *DatastoreSessionStore) Save(r *http.Request, w http.ResponseWriter, key string, info *sessions.SessionInfo) (flag bool, err error)
- func (s *DatastoreSessionStore) SetEncoders(encoders ...sessions.SessionEncoder)
- type MemcacheSessionStore
- func (s *MemcacheSessionStore) Encoders() []sessions.SessionEncoder
- func (s *MemcacheSessionStore) Load(r *http.Request, key string, info *sessions.SessionInfo)
- func (s *MemcacheSessionStore) Save(r *http.Request, w http.ResponseWriter, key string, info *sessions.SessionInfo) (flag bool, err error)
- func (s *MemcacheSessionStore) SetEncoders(encoders ...sessions.SessionEncoder)
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatastoreSessionStore ¶
type DatastoreSessionStore struct {
// contains filtered or unexported fields
}
DatastoreSessionStore stores session data in App Engine's datastore.
func (*DatastoreSessionStore) Encoders ¶
func (s *DatastoreSessionStore) Encoders() []sessions.SessionEncoder
Encoders returns the encoders for this store.
func (*DatastoreSessionStore) Load ¶
func (s *DatastoreSessionStore) Load(r *http.Request, key string, info *sessions.SessionInfo)
Load loads a session for the given key.
func (*DatastoreSessionStore) Save ¶
func (s *DatastoreSessionStore) Save(r *http.Request, w http.ResponseWriter, key string, info *sessions.SessionInfo) (flag bool, err error)
Save saves the session in the response.
func (*DatastoreSessionStore) SetEncoders ¶
func (s *DatastoreSessionStore) SetEncoders(encoders ...sessions.SessionEncoder)
SetEncoders sets a group of encoders in the store.
type MemcacheSessionStore ¶
type MemcacheSessionStore struct {
// contains filtered or unexported fields
}
MemcacheSessionStore stores session data in App Engine's memcache.
func (*MemcacheSessionStore) Encoders ¶
func (s *MemcacheSessionStore) Encoders() []sessions.SessionEncoder
Encoders returns the encoders for this store.
func (*MemcacheSessionStore) Load ¶
func (s *MemcacheSessionStore) Load(r *http.Request, key string, info *sessions.SessionInfo)
Load loads a session for the given key.
func (*MemcacheSessionStore) Save ¶
func (s *MemcacheSessionStore) Save(r *http.Request, w http.ResponseWriter, key string, info *sessions.SessionInfo) (flag bool, err error)
Save saves the session in the response.
func (*MemcacheSessionStore) SetEncoders ¶
func (s *MemcacheSessionStore) SetEncoders(encoders ...sessions.SessionEncoder)
SetEncoders sets a group of encoders in the store.