Help us shape the future of Go! Take the 2026 Go Developer Survey

settings

package
v0.18.5 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package settings is the key/value settings store. Keys are namespaced ("site.title", "seo.default_image"); values are stored as JSON.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("settings: not found")

ErrNotFound is returned by Get when the key does not exist.

Functions

func Migrations

func Migrations() fs.FS

Migrations returns the settings table migrations ("migrations/NNNN_x.sql").

Types

type Store

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

Store reads and writes settings. Get/GetString results are memoized in process memory. The cache is dropped whenever settings_revision.n changes (triggers advance it on every committed settings write, from any connection or process, including e2e helpers that UPDATE settings directly) and on every Store write path.

func New

func New(d *sql.DB) *Store

New returns a store on d logging to slog.Default(). The settings migrations must already be applied.

func (*Store) All

func (s *Store) All(ctx context.Context, prefix string) (map[string]json.RawMessage, error)

All returns every setting whose key starts with prefix ("" for all).

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete removes key; a missing key is not an error. Like Set, never call it inside db.InTx.

func (*Store) DeletePrefix

func (s *Store) DeletePrefix(ctx context.Context, prefix string) error

DeletePrefix removes every key starting with prefix (e.g. "ext.shop."). An empty prefix is refused: it would delete every setting. Never call it inside db.InTx; use DeletePrefixTx there.

func (*Store) DeletePrefixTx

func (s *Store) DeletePrefixTx(ctx context.Context, tx *sql.Tx, prefix string) error

DeletePrefixTx is DeletePrefix inside tx.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string, out any) error

Get unmarshals the JSON value of key into out, or returns ErrNotFound.

func (*Store) GetString

func (s *Store) GetString(ctx context.Context, key, def string) string

GetString returns the string value of key, or def when it is missing. Other failures (DB errors, non-string values) are logged and return def.

func (*Store) Invalidate added in v0.11.0

func (s *Store) Invalidate()

Invalidate drops the process memo. Safe after out-of-band SQL writes when callers mutate the DB outside Store; write paths call this too.

func (*Store) Set

func (s *Store) Set(ctx context.Context, key string, v any) error

Set stores v (marshalled to JSON) under key, replacing any previous value.

Set writes on its own pool connection: never call it inside db.InTx (it would wait on the transaction's lock for busy_timeout and fail). Use SetTx inside a transaction, or call Set after commit.

func (*Store) SetTx

func (s *Store) SetTx(ctx context.Context, tx *sql.Tx, key string, v any) error

SetTx is Set inside tx.

func (*Store) WithLogger

func (s *Store) WithLogger(l *slog.Logger) *Store

WithLogger returns a copy of the store that logs to l, sharing the same process cache as s.

Directories

Path Synopsis
Package settingsmod is the settings kernel.Module.
Package settingsmod is the settings kernel.Module.

Jump to

Keyboard shortcuts

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