pgsessionstore

package
v1.43.7 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: EUPL-1.2 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBConn

type DBConn interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, optionsAndArgs ...interface{}) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, optionsAndArgs ...interface{}) pgx.Row
	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
}

type PGSession

type PGSession struct {
	ID        int64
	Key       string
	Data      string
	CreatedAt time.Time
	UpdatedAt time.Time
	ExpiresOn time.Time
}

PGSession type

type PGStore

type PGStore struct {
	Codecs  []securecookie.Codec
	Options *sessions.Options
	Path    string
	// contains filtered or unexported fields
}

PGStore represents the currently configured session store.

func New

func New(lgr *logger.Logger, db DBConn, keyPairs ...[]byte) (*PGStore, error)

New creates a new PGStore instance.

func (*PGStore) CountExpiredSessions

func (db *PGStore) CountExpiredSessions(ctx context.Context) (int64, error)

func (*PGStore) Get

func (db *PGStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get Fetches a session for a given name after it has been added to the registry.

func (*PGStore) MaxAge

func (db *PGStore) 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 (*PGStore) MaxLength

func (db *PGStore) 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 session, use with caution. The default for a new PGStore is 4096. PostgreSQL allows for max value sizes of up to 1GB (http://www.postgresql.org/docs/current/interactive/datatype-character.html)

func (*PGStore) New

func (db *PGStore) New(r *http.Request, name string) (*sessions.Session, error)

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

func (*PGStore) Save

func (db *PGStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save saves the given session into the database and deletes cookies if needed

func (*PGStore) StartCleanup

func (db *PGStore) StartCleanup(interval time.Duration) (quit chan<- struct{}, done <-chan struct{})

Cleanup runs a background goroutine every interval that deletes expired sessions from the database.

The design is based on https://github.com/yosssi/boltstore

func (*PGStore) StopCleanup

func (db *PGStore) StopCleanup(quit chan<- struct{}, done <-chan struct{})

StopCleanup stops the background cleanup from running.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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