configstore

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package configstore provides storage backends for platform configuration. It supports two modes: file (read-only, config from YAML) and database (read-write, config persisted in PostgreSQL with versioning).

The store works with raw YAML bytes to avoid import cycles with the platform package. The platform is responsible for marshaling/unmarshaling.

Index

Constants

This section is empty.

Variables

View Source
var ErrReadOnly = errors.New("config store is read-only")

ErrReadOnly is returned when a write operation is attempted on a read-only store.

Functions

This section is empty.

Types

type FileStore

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

FileStore wraps an in-memory config loaded from a YAML file. It is read-only: Save always returns ErrReadOnly.

func NewFileStore

func NewFileStore(cfg any) *FileStore

NewFileStore creates a FileStore by marshaling the given config to YAML. The config parameter is typed as any to avoid import cycles with the platform package.

func (*FileStore) History

func (*FileStore) History(_ context.Context, _ int) ([]Revision, error)

History returns nil because file-based config has no version history.

func (*FileStore) Load

func (s *FileStore) Load(_ context.Context) ([]byte, error)

Load returns the config as YAML bytes.

func (*FileStore) Mode

func (*FileStore) Mode() string

Mode returns "file".

func (*FileStore) Save

func (*FileStore) Save(_ context.Context, _ []byte, _ SaveMeta) error

Save returns ErrReadOnly because file-based config is immutable.

type Revision

type Revision struct {
	ID        int       `json:"id"`
	Version   int       `json:"version"`
	Author    string    `json:"author"`
	Comment   string    `json:"comment"`
	CreatedAt time.Time `json:"created_at"`
}

Revision describes a historical configuration version.

type SaveMeta

type SaveMeta struct {
	Author  string
	Comment string
}

SaveMeta holds metadata for a config save operation.

type Store

type Store interface {
	// Load returns the stored configuration as YAML bytes, or nil if no config exists (first boot).
	Load(ctx context.Context) ([]byte, error)
	// Save persists a configuration snapshot (YAML bytes) with metadata.
	Save(ctx context.Context, data []byte, meta SaveMeta) error
	// History returns recent configuration revisions, newest first.
	History(ctx context.Context, limit int) ([]Revision, error)
	// Mode returns the store mode: "file" or "database".
	Mode() string
}

Store provides configuration storage and retrieval using raw YAML bytes.

Directories

Path Synopsis
Package postgres provides a PostgreSQL-backed config store with versioning.
Package postgres provides a PostgreSQL-backed config store with versioning.

Jump to

Keyboard shortcuts

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