postgres

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package postgres implements gouncer's user and session persistence in a PostgreSQL schema of its own.

Index

Constants

This section is empty.

Variables

View Source
var Migrations embed.FS

Migrations holds the auth schema migration files applied by goose.

Functions

func Migrate

func Migrate(ctx context.Context, databaseURL string) error

Migrate applies the auth schema migrations to the database at databaseURL.

Types

type UserStore

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

UserStore persists users and their sessions in the auth schema.

func NewUserStore

func NewUserStore(pool *pgxpool.Pool) *UserStore

NewUserStore returns a UserStore backed by pool.

func (*UserStore) CreateSession

func (s *UserStore) CreateSession(ctx context.Context, session gouncer.Session) error

CreateSession stores a login session.

func (*UserStore) CreateUser

func (s *UserStore) CreateUser(ctx context.Context, u gouncer.User) error

CreateUser stores a new user, or gouncer.ErrEmailTaken when the email is already in use.

func (*UserStore) DeleteExpiredSessions

func (s *UserStore) DeleteExpiredSessions(ctx context.Context, now time.Time) (int64, error)

DeleteExpiredSessions removes sessions that expired at or before now and returns how many it removed.

func (*UserStore) DeleteSession

func (s *UserStore) DeleteSession(ctx context.Context, tokenHash []byte) error

DeleteSession removes the session with the given token hash, if any.

func (*UserStore) ListUsers

func (s *UserStore) ListUsers(ctx context.Context) ([]gouncer.User, error)

ListUsers returns every user ordered by name. The listing never reads password hashes, so the returned users carry none.

func (*UserStore) SetUserDisabled

func (s *UserStore) SetUserDisabled(ctx context.Context, id uuid.UUID, disabled bool) error

SetUserDisabled updates whether the user may log in, revoking every session the user holds when disabling so a later re-enable cannot resurrect them, or returns gouncer.ErrUserNotFound when no such user exists.

func (*UserStore) UserByEmail

func (s *UserStore) UserByEmail(ctx context.Context, email string) (gouncer.User, error)

UserByEmail returns the user owning the email, or gouncer.ErrUserNotFound if none exists.

func (*UserStore) UserBySession

func (s *UserStore) UserBySession(ctx context.Context, tokenHash []byte, now time.Time) (gouncer.User, error)

UserBySession returns the enabled user owning an unexpired session with the given token hash, or gouncer.ErrSessionNotFound.

Directories

Path Synopsis
internal
db
Package testdb provides pgtestdb wiring for tests against the module's auth schema.
Package testdb provides pgtestdb wiring for tests against the module's auth schema.

Jump to

Keyboard shortcuts

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