コード例 #1
0
func (d *dalStore) delete(session *gSessions.Session) error {
	if !dal.IsObjectIDHex(session.ID) {
		return nSessions.ErrInvalidId
	}

	conn := d.connection.Clone()
	defer conn.Close()
	db := conn.DB(d.database)
	c := db.C(d.collection)

	return c.RemoveID(dal.ObjectIDHex(session.ID))
}
コード例 #2
0
func (d *dalStore) load(session *gSessions.Session) (bool, error) {
	if !dal.IsObjectIDHex(session.ID) {
		return false, nSessions.ErrInvalidId
	}
	conn := d.connection.Clone()
	defer conn.Close()
	db := conn.DB(d.database)
	c := db.C(d.collection)

	s := dalSession{}
	err := c.FindID(dal.ObjectIDHex(session.ID)).One(&s)
	if err != nil {
		return false, err
	}
	if err := securecookie.DecodeMulti(session.Name(), s.Data, &session.Values, d.Codecs...); err != nil {
		return false, err
	}
	return true, nil
}
コード例 #3
0
func (d *dalStore) save(session *gSessions.Session) error {
	if !dal.IsObjectIDHex(session.ID) {
		return nSessions.ErrInvalidId
	}

	conn := d.connection.Clone()
	defer conn.Close()
	db := conn.DB(d.database)
	c := db.C(d.collection)

	var modified time.Time
	if val, ok := session.Values["modified"]; ok {
		modified, ok = val.(time.Time)
		if !ok {
			return nSessions.ErrInvalidModified
		}
	} else {
		modified = time.Now()
	}

	encoded, err := securecookie.EncodeMulti(session.Name(), session.Values, d.Codecs...)
	if err != nil {
		return err
	}

	id := dal.ObjectIDHex(session.ID)
	s := dalSession{
		ID:       id,
		Data:     encoded,
		Modified: modified,
	}

	_, err = c.SaveID(id, &s)
	if err != nil {
		return err
	}

	return nil
}