Documentation
¶
Overview ¶
Package settings is the key/value settings store. Keys are namespaced ("site.title", "seo.default_image"); values are stored as JSON.
Index ¶
- Variables
- func Migrations() fs.FS
- type Store
- func (s *Store) All(ctx context.Context, prefix string) (map[string]json.RawMessage, error)
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) DeletePrefix(ctx context.Context, prefix string) error
- func (s *Store) DeletePrefixTx(ctx context.Context, tx *sql.Tx, prefix string) error
- func (s *Store) Get(ctx context.Context, key string, out any) error
- func (s *Store) GetString(ctx context.Context, key, def string) string
- func (s *Store) Set(ctx context.Context, key string, v any) error
- func (s *Store) SetTx(ctx context.Context, tx *sql.Tx, key string, v any) error
- func (s *Store) WithLogger(l *slog.Logger) *Store
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("settings: not found")
ErrNotFound is returned by Get when the key does not exist.
Functions ¶
func Migrations ¶
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.
func New ¶
New returns a store on d logging to slog.Default(). The settings migrations must already be applied.
func (*Store) Delete ¶
Delete removes key; a missing key is not an error. Like Set, never call it inside db.InTx.
func (*Store) DeletePrefix ¶
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 ¶
DeletePrefixTx is DeletePrefix inside tx.
func (*Store) GetString ¶
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) Set ¶
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.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package settingsmod is the settings kernel.Module.
|
Package settingsmod is the settings kernel.Module. |