mongostore.go
func NewMongoStore(c *mgo.Collection, maxAge int, ensureTTL bool,
	keyPairs ...[]byte) *MongoStore {
	store := &MongoStore{
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: maxAge,
		},
		Token: &CookieToken{},
		coll:  c,
	}

	store.MaxAge(maxAge)

	if ensureTTL {
		c.EnsureIndex(mgo.Index{
			Key:         []string{"modified"},
			Background:  true,
			Sparse:      true,
			ExpireAfter: time.Duration(maxAge) * time.Second,
		})
	}

	return store
}
func NewMongoStore(c *mgo.Collection, maxAge int, ensureTTL bool,
	keyPairs ...[]byte) *MongoStore {
	store := &MongoStore{
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: maxAge,
		},
		Token: &CookieToken{},
		coll:  c,
	}

	store.MaxAge(maxAge)

	if ensureTTL {
		c.EnsureIndex(mgo.Index{
			Key:         []string{"modified"},
			Background:  true,
			Sparse:      true,
			ExpireAfter: time.Duration(maxAge) * time.Second,
		})
	}

	return store
}
func NewMongoStore ( c * mgo . Collection , maxAge int , ensureTTL bool , keyPairs ... [ ] byte ) * MongoStore { store := & MongoStore { Codecs : securecookie . CodecsFromPairs ( keyPairs ... ) , Options : & sessions . Options { Path : " " , MaxAge : maxAge , } , Token : & CookieToken { } , coll : c , } store . MaxAge ( maxAge ) if ensureTTL { c . EnsureIndex ( mgo . Index { Key : [ ] string { " " } , Background : true , Sparse : true , ExpireAfter : time . Duration ( maxAge ) * time . Second , } ) } return store }
// NewMongoStore returns a new MongoStore.
// Set ensureTTL to true let the database auto-remove expired object by maxAge.
NewMongoStore returns a new MongoStore . Set ensureTTL to true let the database auto - remove expired object by maxAge .