Documentation ¶
Overview ¶
mongostore contains gorilla session store.
Index ¶
- type MongoStore
- func (s *MongoStore) ExpireSessions(user string, provider string) error
- func (s *MongoStore) Get(r *http.Request, name string) (*sessions.Session, error)
- func (s *MongoStore) GetActiveSessionsCount() (int64, error)
- func (s *MongoStore) New(r *http.Request, name string) (*sessions.Session, error)
- func (s *MongoStore) Save(_ *http.Request, w http.ResponseWriter, session *sessions.Session) error
- func (s *MongoStore) StartAutoClean(ctx context.Context, timeout time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MongoStore ¶
type MongoStore struct { Codecs []securecookie.Codec Options *sessions.Options // default configuration // contains filtered or unexported fields }
MongoStore stores sessions in mongo db.
func NewStore ¶
func NewStore(client mongo.DbClient, keyPairs ...[]byte) *MongoStore
NewStore creates new mongo store.
The client argument is the mongo db client where sessions will be saved.
Keys are defined in pairs to allow key rotation, but the common case is to set a single authentication key and optionally an encryption key.
The first key in a pair is used for authentication and the second for encryption. The encryption key can be set to nil or omitted in the last pair, but the authentication key is required in all pairs.
It is recommended to use an authentication key with 32 or 64 bytes. The encryption key, if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.
func (*MongoStore) ExpireSessions ¶
func (s *MongoStore) ExpireSessions(user string, provider string) error
func (*MongoStore) 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 (*MongoStore) GetActiveSessionsCount ¶
func (s *MongoStore) GetActiveSessionsCount() (int64, error)
func (*MongoStore) 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 (*MongoStore) Save ¶
func (s *MongoStore) Save(_ *http.Request, w http.ResponseWriter, session *sessions.Session) error
Save adds a single session to the response.
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.
func (*MongoStore) StartAutoClean ¶
func (s *MongoStore) StartAutoClean(ctx context.Context, timeout time.Duration)