chiefpref

package
v0.294.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chiefpref stores each user's choice to turn their chief on or off (migration 0060, chief_preferences). It stores only the CHOICE: whether the chief is on for a user who never chose is internal/api's rule (chiefOn), so the default lives in one place.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotOwner = errors.New("chiefpref: the toggle is read only as its owner or as the system")

ErrNotOwner refuses a read whose ctx can see neither owner's row nor every row.

Functions

This section is empty.

Types

type PG

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

PG is Store on chief_preferences, under row-level security.

func NewPG

func NewPG(pool *pgxpool.Pool) *PG

NewPG is Store over pool.

func (*PG) Choice

func (p *PG) Choice(ctx context.Context, owner int64) (bool, bool, error)

Choice implements Store.

🔴 IT REFUSES A ctx THAT ROW-LEVEL SECURITY WOULD BLIND. A row of owner's is invisible to any other user's principal and to a principal-less ctx, and an invisible row reads as "never chose", which falls back to "on if a chief agent exists": a user who turned their chief OFF would get it back on any path that read the toggle with the wrong principal. So only owner's own principal or the system scope may read, and anything else is an error the caller reads as off.

func (*PG) SetEnabled

func (p *PG) SetEnabled(ctx context.Context, owner int64, on bool) error

SetEnabled implements Store: the CALLER's row (row-level security refuses another owner's).

type Store

type Store interface {
	// Choice is owner's stored choice: chose is false when owner never
	// turned the chief on or off (no row), and on is then meaningless.
	Choice(ctx context.Context, owner int64) (chose, on bool, err error)
	// SetEnabled records owner's choice.
	SetEnabled(ctx context.Context, owner int64, on bool) error
}

Store is the per-user chief toggle.

Jump to

Keyboard shortcuts

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