runtimeconfig

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package runtimeconfig loads strict YAML runtime configuration through one interpolation boundary.

Index

Constants

View Source
const (
	// DefaultConfigPath is the conventional runtime config file name.
	DefaultConfigPath = "config.yml"
)

Variables

View Source
var (
	// ErrInvalidOptions reports an invalid loader declaration.
	ErrInvalidOptions = errors.New("runtimeconfig.invalid_options")
	// ErrInvalidValueMapping reports a non-scalar effective value mapping.
	ErrInvalidValueMapping = errors.New("runtimeconfig.invalid_value_mapping")
	// ErrMissingConfig reports a missing runtime config file.
	ErrMissingConfig = errors.New("runtimeconfig.missing_config")
	// ErrMissingSection reports a missing required config section.
	ErrMissingSection = errors.New("runtimeconfig.missing_section")
	// ErrParse reports malformed YAML or target decode failures.
	ErrParse = errors.New("runtimeconfig.parse")
	// ErrRead reports config file read failures.
	ErrRead = errors.New("runtimeconfig.read")
	// ErrValidation reports application validation failures after strict decode.
	ErrValidation = errors.New("runtimeconfig.validation")
)

Functions

This section is empty.

Types

type ConfigValues

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

ConfigValues exposes selected scalar values from the effective config.

func (ConfigValues) Lookup

func (values ConfigValues) Lookup(key string) (string, bool)

Lookup resolves a config value by key.

func (ConfigValues) Map

func (values ConfigValues) Map() map[string]string

Map returns a defensive copy of all config values.

func (ConfigValues) Resolve

func (values ConfigValues) Resolve(key string) string

Resolve returns a config value by key, or empty string when absent.

func (ConfigValues) Resolver

func (values ConfigValues) Resolver() func(string) string

Resolver returns a legacy string resolver backed by effective config values.

type Contract

type Contract[Config any] struct {
	DefaultConfigPath string
	ExpansionLookup   ExpansionLookup
	ValueMappings     []ValueMapping
	Validate          func(Config) error
}

Contract declares a typed runtime config shape and loading behavior.

type ExpansionLookup

type ExpansionLookup func(name string) (string, bool)

ExpansionLookup resolves one YAML interpolation reference.

type Loaded

type Loaded[Config any] struct {
	Path          string
	Config        Config
	Settings      map[string]any
	Values        ConfigValues
	EffectiveYAML []byte
}

Loaded contains the typed config and reusable effective-config surfaces.

type Loader

type Loader[Config any] struct {
	// contains filtered or unexported fields
}

Loader loads typed runtime config values.

func NewLoader

func NewLoader[Config any](contract Contract[Config]) (Loader[Config], error)

NewLoader creates a typed runtime config loader.

func (Loader[Config]) Load

func (loader Loader[Config]) Load(configPath string) (Loaded[Config], error)

Load reads, validates, expands, and decodes a complete runtime config file.

func (Loader[Config]) LoadSection

func (loader Loader[Config]) LoadSection(configPath string, sectionPath []string) (Loaded[Config], error)

LoadSection reads, validates, expands, and decodes one required YAML section.

func (Loader[Config]) ResolvePath

func (loader Loader[Config]) ResolvePath(configPath string) (string, error)

ResolvePath resolves an explicit config path or the loader default.

type ValueMapping

type ValueMapping struct {
	Key  string
	Path []string
}

ValueMapping maps a scalar YAML path into the effective config value map.

Jump to

Keyboard shortcuts

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