runtimesettings

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("runtime setting not found")
	ErrLocked   = errors.New("runtime setting is managed externally")
	ErrInvalid  = errors.New("invalid runtime setting value")
)

Functions

This section is empty.

Types

type MongoDBStore

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

MongoDBStore persists runtime settings in MongoDB.

func NewMongoDBStore

func NewMongoDBStore(_ context.Context, database *mongo.Database) (*MongoDBStore, error)

NewMongoDBStore uses the shared runtime_settings collection.

func (*MongoDBStore) Get

func (s *MongoDBStore) Get(ctx context.Context, key string) (string, bool, error)

Get returns a persisted value when present.

func (*MongoDBStore) GetAll added in v0.2.3

func (s *MongoDBStore) GetAll(ctx context.Context) (map[string]string, error)

GetAll returns every persisted value by key.

func (*MongoDBStore) Replace added in v0.1.107

func (s *MongoDBStore) Replace(ctx context.Context, key, old, value string) (string, error)

Replace updates key to value only while it still holds old, then reads back the winner. The filtered update is atomic on the document, so of two instances replacing the same old value only one does.

func (*MongoDBStore) Set

func (s *MongoDBStore) Set(ctx context.Context, key, value string) error

Set upserts a persisted value.

func (*MongoDBStore) SetDefault added in v0.1.85

func (s *MongoDBStore) SetDefault(ctx context.Context, key, value string) (string, error)

SetDefault inserts value unless key exists, then reads back the winner. An upsert with $setOnInsert is atomic on the _id, so two instances initialising at once cannot both believe they won.

type SQLStore

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

SQLStore persists runtime settings in SQLite or PostgreSQL.

func NewSQLStore

func NewSQLStore(ctx context.Context, db sqlx.DB) (*SQLStore, error)

NewSQLStore initializes the shared runtime-settings table.

func (*SQLStore) Get

func (s *SQLStore) Get(ctx context.Context, key string) (string, bool, error)

Get returns a persisted value when present.

func (*SQLStore) GetAll added in v0.2.3

func (s *SQLStore) GetAll(ctx context.Context) (map[string]string, error)

GetAll returns every persisted value by key.

func (*SQLStore) Replace added in v0.1.107

func (s *SQLStore) Replace(ctx context.Context, key, old, value string) (string, error)

Replace updates key to value only while it still holds old, then reads back the winner. The conditional UPDATE is atomic in both SQLite and PostgreSQL, so of two instances replacing the same old value only one does.

func (*SQLStore) Set

func (s *SQLStore) Set(ctx context.Context, key, value string) error

Set upserts a persisted value.

func (*SQLStore) SetDefault added in v0.1.85

func (s *SQLStore) SetDefault(ctx context.Context, key, value string) (string, error)

SetDefault inserts value unless key exists, then reads back the winner. ON CONFLICT DO NOTHING is atomic in both SQLite and PostgreSQL, so two instances inserting at once cannot both believe they won.

type Service

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

Service validates, persists, applies, and reconciles registered settings.

func New

func New(ctx context.Context, backend storage.Storage, registered []ext.RuntimeSetting) (*Service, error)

New restores registered settings and starts cross-instance reconciliation.

func (*Service) Close

func (s *Service) Close() error

Close stops background reconciliation.

func (*Service) List

func (s *Service) List() []ext.SettingDescriptor

List returns the current setting descriptors in stable key order.

func (*Service) Update

func (s *Service) Update(ctx context.Context, key, value string) (ext.SettingDescriptor, error)

Update applies and persists one setting, rolling back if persistence fails.

type Store

type Store interface {
	Get(ctx context.Context, key string) (value string, found bool, err error)
	// GetAll returns every persisted value by key in one read.
	GetAll(ctx context.Context) (map[string]string, error)
	Set(ctx context.Context, key, value string) error
	// SetDefault stores value only when key has no value yet, and returns
	// whatever is stored afterwards: value, or the one that was already
	// there. It is atomic, so instances racing to initialise the same key
	// all end up with the same winner.
	SetDefault(ctx context.Context, key, value string) (string, error)
	// Replace stores value only when key still holds old, and returns
	// whatever is stored afterwards: value, or the one another instance
	// wrote first. It is atomic, so instances racing to replace the same
	// value all end up with the same winner.
	Replace(ctx context.Context, key, old, value string) (string, error)
}

Store persists deployment-wide runtime-setting values.

func NewStore added in v0.1.85

func NewStore(ctx context.Context, backend storage.Storage) (Store, error)

NewStore opens the deployment-wide key/value store on the shared backend. Besides the registered settings it holds other small per-deployment state that must live with the database rather than the filesystem, such as the install identifier.

Jump to

Keyboard shortcuts

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