mongostore

package module
v0.0.0-...-648f5d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

README

mongostore

A MongoDB store implementation for gorilla/sessions, based on mongo-driver.

Installation

go get github.com/SpecialFlocon/mongostore

Documentation

Index

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
	// contains filtered or unexported fields
}

MongoStore stores sessions in a MongoDB collection.

func NewMongoStore

func NewMongoStore(c *mongo.Collection, opts *sessions.Options, keyPairs ...[]byte) *MongoStore

NewMongoStore returns a new MongoStore instance.

func (*MongoStore) Get

func (s *MongoStore) Get(r *http.Request, name string) (*sessions.Session, error)

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) MaxAge

func (s *MongoStore) MaxAge(age int)

MaxAge sets the maximum age for the store and the underlying cookie implementation. Individual sessions can be deleted by setting Options.MaxAge = -1 for that session.

func (*MongoStore) New

func (s *MongoStore) New(r *http.Request, name string) (*sessions.Session, error)

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(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save adds a single session to the response.

type Session

type Session struct {
	ID         primitive.ObjectID `bson:"_id,omitempty"`
	Data       string             `bson:"data"`
	ModifiedAt time.Time          `bson:"modifiedAt"`
}

Session is the model for a session document.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL