settings

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package settings is a platform module: business settings of the project, stored in the database and editable without a deploy.

The schema is generated from settings.yaml and comes from project code; the module adds storage, caching, refresh and the store in the container.

Index

Constants

View Source
const DefaultTable = "platform_settings"

DefaultTable is where overrides are stored.

Variables

This section is empty.

Functions

func Store

func Store(app *platform.App) *settingsx.Store

Store returns the store from the container.

Types

type Config

type Config struct {
	Table string // table holding the overrides

	// RefreshInterval is how often values are re-read, so a change made on one instance
	// reaches the others. Zero disables the refresh loop.
	RefreshInterval time.Duration
}

Config holds module settings. Load fills it from the environment; the platform generator writes the Load call into the project's config.gen.go.

func Load

func Load(l *confx.Loader) Config

Load reads the module settings from environment variables.

type Module

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

Module implements platform.Module.

func New

func New(cfg Config, schema settingsx.Schema) *Module

New creates the module from ready settings and the project schema.

func (*Module) Health

func (m *Module) Health(context.Context) error

Health fails when the settings cannot be re-read: the application still works on the cached values, yet a change would not reach it, and that must be visible.

func (*Module) Init

func (m *Module) Init(ctx context.Context, app *platform.App) error

Init creates the table, loads the values and puts the store into the container, where project code picks it up through the generated accessors.

func (*Module) Name

func (m *Module) Name() string

func (*Module) Start

func (m *Module) Start(ctx context.Context) error

Start begins the refresh loop: a value changed on one instance takes effect on the others within RefreshInterval, with no restart and no deploy.

func (*Module) Stop

func (m *Module) Stop(context.Context) error

Stop ends the refresh loop.

type Querier added in v0.9.0

type Querier interface {
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
}

Querier runs a query: *pgxpool.Pool, *pgx.Conn and pgx.Tx all fit.

type Report added in v0.9.0

type Report = settingsx.ImportReport

Report says what an import did with every key; see settingsx.ImportReport.

func Import added in v0.9.0

func Import(ctx context.Context, app *platform.App, values map[string]string, by string) (Report, error)

Import moves settings kept elsewhere into the settings of the module, storing only the values that differ from the defaults of the schema. It is safe to repeat; see settingsx.Store.Import for the rules. The settings module must be initialised, so a project calls it from wireDomain or from a command built on the platform.

func ImportQuery added in v0.9.0

func ImportQuery(ctx context.Context, app *platform.App, db Querier, query, by string) (Report, error)

ImportQuery imports the settings a query returns. The query yields two text columns, the key and the value, for example

SELECT key, value FROM app_configs

A NULL value means "use the default", the way taply's app_configs stores it, so it is imported as the default of the schema: nothing is stored, and the key is reported among the defaults, the kept or the unknown keys.

Jump to

Keyboard shortcuts

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