session

package
v0.0.0-...-78f4eb6 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

internal/session/manager.go

internal/session/store.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PostgresStore

type PostgresStore struct {
	// contains filtered or unexported fields
}

func NewPostgresStore

func NewPostgresStore(db *pgxpool.Pool, queries *generated.Queries, logger *slog.Logger) *PostgresStore

func (*PostgresStore) All

func (p *PostgresStore) All(ctx context.Context) (map[string][]byte, error)

All returns a map containing the token and data for all active (i.e. not expired) sessions.

func (*PostgresStore) Cleanup

func (p *PostgresStore) Cleanup(ctx context.Context) error

Cleanup deletes expired session data from the PostgresStore instance.

func (*PostgresStore) Commit

func (p *PostgresStore) Commit(ctx context.Context, token string, b []byte, expiry time.Time) error

Commit adds a session token and data to the PostgresStore instance with the given expiry time. If the session token already exists, then the data and expiry time are updated.

func (*PostgresStore) Delete

func (p *PostgresStore) Delete(ctx context.Context, token string) error

Delete removes a session token and corresponding data from the PostgresStore instance.

func (*PostgresStore) Find

func (p *PostgresStore) Find(ctx context.Context, token string) (b []byte, exists bool, err error)

Find returns the data for a given session token from the PostgresStore instance. If the session token is not found or is expired, the returned exists flag will be false.

type SessionManager

type SessionManager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(store Store, lifetime time.Duration, logger *slog.Logger) *SessionManager

func (*SessionManager) Cleanup

func (s *SessionManager) Cleanup(ctx context.Context) error

Cleanup is exposed to allow the session store to cleanup expired sessions

func (*SessionManager) Destroy

func (s *SessionManager) Destroy(ctx context.Context, c *echo.Context) error

Destroy deletes the session data and expires the session cookie.

func (*SessionManager) Load

func (s *SessionManager) Load(ctx context.Context, c *echo.Context) (map[string]any, error)

Load retrieves the session data for the given request.

func (*SessionManager) RenewToken

func (s *SessionManager) RenewToken(ctx context.Context, c *echo.Context) error

RenewToken updates the session token while preserving the session data.

func (*SessionManager) Save

func (s *SessionManager) Save(ctx context.Context, c *echo.Context, values map[string]any) error

Save persists the session data and writes the session cookie.

type Store

type Store interface {
	Find(ctx context.Context, token string) (b []byte, exists bool, err error)
	Commit(ctx context.Context, token string, b []byte, expiry time.Time) error
	Delete(ctx context.Context, token string) error
	Cleanup(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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