sqlitestore

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2023 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Overview

Package sqlitestore store provides a sqlite-backed session store using database.DB

Index

Constants

This section is empty.

Variables

View Source
var MigrationFiles []string = []string{
	"1-initialize-schema-v0.3.0",
}

Functions

func NewDomainEmbeds

func NewDomainEmbeds() database.DomainEmbeds

Types

type Session

type Session struct {
	ID               string
	Data             string // Data is expected to be a base64-encoded string
	CreationTime     time.Time
	ModificationTime time.Time
	ExpirationTime   time.Time
}

type SqliteStore

type SqliteStore struct {
	Codecs          []securecookie.Codec
	Options         *sessions.Options
	AbsoluteTimeout time.Duration
	// contains filtered or unexported fields
}

SqliteStore stores sessions in a godest sqlite-backed database.DB.

func NewSqliteStore

func NewSqliteStore(
	db *database.DB, absoluteTimeout time.Duration, keyPairs ...[]byte,
) *SqliteStore

NewSqliteStore returns a new SqliteStore.

The db argument should be a database.DB with a "sessions_session" table already initialized according to the schema defined by the migrations in NewDomainEmbeds.

See sessions.NewCookieStore for a description of the other parameters.

func NewStore

func NewStore(db *database.DB, c session.Config) (store *session.Store, backingStore *SqliteStore)

func (*SqliteStore) AddSession

func (ss *SqliteStore) AddSession(ctx context.Context, sess Session) (err error)

func (*SqliteStore) Cleanup added in v0.5.1

func (ss *SqliteStore) Cleanup(ctx context.Context) (done bool, err error)

func (*SqliteStore) DeleteExpiredSessions

func (ss *SqliteStore) DeleteExpiredSessions(ctx context.Context, threshold time.Time) (err error)

func (*SqliteStore) DeleteOldCreatedSessions added in v0.5.1

func (ss *SqliteStore) DeleteOldCreatedSessions(
	ctx context.Context, timeout time.Duration, threshold time.Time,
) (err error)

func (*SqliteStore) DeleteSession

func (ss *SqliteStore) DeleteSession(ctx context.Context, id string) (err error)

func (*SqliteStore) Get

func (ss *SqliteStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get returns a session for the given name after adding it to the registry.

See sessions.CookieStore.Get.

func (*SqliteStore) GetSession

func (ss *SqliteStore) GetSession(ctx context.Context, id string) (sess Session, err error)

func (*SqliteStore) MaxAge

func (ss *SqliteStore) MaxAge(age int)

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

func (*SqliteStore) MaxLength

func (ss *SqliteStore) MaxLength(l int)

MaxLength restricts the maximum length of new sessions to l. If l is 0 there is no limit to the size of a sesson, use with caution. The default for a new SqliteStore is 4096 (default for securecookie).

func (*SqliteStore) New

func (ss *SqliteStore) New(r *http.Request, name string) (*sessions.Session, error)

New creates and returns a session for the given name without adding it to the registry.

See sessions.CookieStore.New.

func (*SqliteStore) PeriodicallyCleanup

func (ss *SqliteStore) PeriodicallyCleanup(
	ctx context.Context, interval time.Duration,
) error

func (*SqliteStore) Save

Save adds a single session to the response.

If the Options.MaxAge of the session is <= 0 then the session record will be deleted from the database. With this process it properly enforces session cookie handling, so no need to trust the web browser's cookie management.

func (*SqliteStore) UpdateSession

func (ss *SqliteStore) UpdateSession(ctx context.Context, sess Session) (err error)

Jump to

Keyboard shortcuts

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