config

package
v0.0.0-...-b88f92b Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package config provides live configuration reloading and unification functions.

Index

Constants

View Source
const FileDebounce = 10 * time.Millisecond

FileDebounce is the default duration we wait for the contents to have stabilised to work around some editors writing an empty file and then the buffer.

Variables

This section is empty.

Functions

func Validate

func Validate(schema string, cfg any) (paths [][]string, err error)

Validate performs a validation of the provided configuration value, returning a list of invalid paths and a CUE errors.Error explaining the issues found if the configuration is invalid according to the provided schema.

func Vet

func Vet(cfg *System) (paths [][]string, err error)

Vet performs a validation of the provided configuration, returning a list of invalid paths and a CUE errors.Error explaining the issues found if the configuration is invalid. Vet uses Validate with the config.ModuleDependency schema to globally validate module dependencies and then for each service using either the modules custom scheme held in the Module.Schema field, or if that is empty, the config.DeviceDependency schema.

Types

type Button

type Button = config.Button

Alias the publicly visible types.

type Change

type Change struct {
	Event  []fsnotify.Event
	Config *System
	Err    error
}

Change is a set of related configuration changes identified by Watch.

func (Change) Op

func (c Change) Op() fsnotify.Op

Op returns an aggregated fsnotify.Op for all elements of the receivers' Event field.

type Device

type Device = config.Device

Alias the publicly visible types.

type Kernel

type Kernel = config.Kernel

Alias the publicly visible types.

type Manager

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

Manager is a configurations stream manager. It holds a progressive configuration state constructed from applying a sequence of configuration changes.

func NewManager

func NewManager(log *slog.Logger) *Manager

NewManager returns a new Manager.

func (*Manager) Apply

func (m *Manager) Apply(c Change) error

Apply applies the provided change to the current configuration state. Any error returned will be fs.PathError.

func (*Manager) Fragments

func (m *Manager) Fragments() map[string]*System

Fragments returns the currently held configuration fragments. It is intended only for debugging.

func (*Manager) Unify

func (m *Manager) Unify(schema string) (cfg *System, val cue.Value, included, remain []string, err error)

Unify returns a complete unified configuration validated against the provided CUE schema. The configuration is returned as both a *Config and a cue.Value to allow inspection of incomplete unification. The names of files that are included and those that remain to be included is also returned.

type Module

type Module = config.Module

Alias the publicly visible types.

type Service

type Service = config.Service

Alias the publicly visible types.

type Sum

type Sum = config.Sum

Alias the publicly visible types.

type System

type System = config.System

Alias the publicly visible types.

func Repair

func Repair(cfg *System, paths [][]string) (*System, error)

Repair removes modules and services in cfg that correspond to invalid field paths identified by Vet until no invalid fields are found, and returning the result. Paths referring to invalid fields in the kernel configuration will result in an error. The final result may have no configured module or service.

type Watcher

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

Watcher collects raw fsnotify.Events and aggregates and filters for semantically meaningful configuration changes.

func NewWatcher

func NewWatcher(ctx context.Context, dir string, changes chan<- Change, debounce time.Duration, log *slog.Logger) (*Watcher, error)

NewWatcher starts an fsnotify.Watcher for the provided directory, sending change events on the changes channel. If dir is deleted, it is recreated as a new directory and a new watcher is set. The debounce parameter specifies how long to wait after an fsnotify.Event before reading the file to ensure that writes will be reflected in the state checksum. If it is less than zero, FileDebounce is used.

func (*Watcher) Watch

func (w *Watcher) Watch(ctx context.Context) error

Watch processes the receiver's fsnotify.Watcher events, performing aggregation and semantic filtering.

Jump to

Keyboard shortcuts

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