Exemplo n.º 1
0
// Save saves the session in the response.
func (s *MemcacheSessionStore) Save(r *http.Request, w http.ResponseWriter,
	key string, info *sessions.SessionInfo) (flag bool, err error) {
	sid, serialized, error := getIdAndData(info)
	if error != nil {
		err = error
		return
	}

	// Add the item to the memcache, if the key does not already exist.
	err = memcache.Add(appengine.NewContext(r), &memcache.Item{
		Key:   sessionKey(sid),
		Value: serialized,
	})
	if err != nil {
		return
	}

	return sessions.SetCookie(s, w, key, cloneInfo(info, sid))
}
Exemplo n.º 2
0
// Save saves the session in the response.
func (s *DatastoreSessionStore) Save(r *http.Request, w http.ResponseWriter,
	key string, info *sessions.SessionInfo) (flag bool, err error) {
	sid, serialized, error := getIdAndData(info)
	if error != nil {
		err = error
		return
	}

	// Save the session.
	c := appengine.NewContext(r)
	entityKey := datastore.NewKey(c, "Session", sessionKey(sid), 0, nil)
	_, err = datastore.Put(appengine.NewContext(r), entityKey, &Session{
		Date:  datastore.SecondsToTime(time.Seconds()),
		Value: serialized,
	})
	if err != nil {
		return
	}

	return sessions.SetCookie(s, w, key, cloneInfo(info, sid))
}