Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MongoDBStore ¶
type MongoDBStore struct {
// contains filtered or unexported fields
}
MongoDBStore stores sessions using mongoDB as backend.
func NewMongoDBStore ¶
func NewMongoDBStore(col *mongo.Collection, keyPairs ...[]byte) (*MongoDBStore, error)
NewMongoDBStore returns a new NewMongoDBStore with default config
defaultConfig := MongoDBStoreConfig{ IndexTTL: true, SessionOptions: sessions.Options{ Path: "/", MaxAge: 3600 * 24 * 30, HttpOnly: true, }, }
func NewMongoDBStoreWithConfig ¶
func NewMongoDBStoreWithConfig(coll *mongo.Collection, cfg MongoDBStoreConfig, keyPairs ...[]byte) (*MongoDBStore, error)
NewMongoDBStoreWithConfig returns a new NewMongoDBStore with a custom MongoDBStoreConfig
func (*MongoDBStore) Get ¶
Get returns a session for the given name after adding it to the registry.
It returns a new session if the sessions doesn't exist. Access IsNew on the session to check if it is an existing session or a new one.
It returns a new session and an error if the session exists but could not be decoded.
func (*MongoDBStore) New ¶
New returns a session for the given name without adding it to the registry.
The difference between New() and Get() is that calling New() twice will decode the session data twice, while Get() registers and reuses the same decoded session after the first call.
func (*MongoDBStore) Save ¶
func (mstore *MongoDBStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
Save adds a single session to the response and persist session in mongoDB collection
If the Options.MaxAge of the session is <= 0 then the session file will be deleted from the store path. With this process it enforces the properly session cookie handling so no need to trust in the cookie management in the web browser.
type MongoDBStoreConfig ¶
type MongoDBStoreConfig struct { // whether to create TTL index(https://docs.mongodb.com/manual/core/index-ttl/) // for the session document IndexTTL bool // gorilla-sessions options SessionOptions sessions.Options }
MongoDBStoreConfig is a configuration options for MongoDBStore