config

package
v0.19.5 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config provides shared configuration primitives for the adaouat CLIs: a strict YAML loader, app-name-parameterized path resolution, and structured validation errors. Schemas, defaults, and merge semantics stay in the apps.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyConfig = errors.New("config: empty config file")

ErrEmptyConfig is returned by Decode/Load when the input has no YAML document (an empty file), so callers can classify it with errors.Is instead of guessing from a raw "EOF".

Functions

func Decode

func Decode(r io.Reader, target any) error

Decode strictly parses YAML from r into target (a pointer to a struct), rejecting unknown fields. Errors are prefixed "config:"; a yaml.TypeError is flattened into a single message joining each field-level error. An empty input returns ErrEmptyConfig.

func ExpandHome added in v0.19.3

func ExpandHome(path string) string

ExpandHome replaces a leading "~" or "~/" with the user's home directory; any other path (including "~user/...") is returned unchanged, as is every path when the home directory cannot be determined.

func Load

func Load(path string, target any) error

Load opens path and decodes it into target via Decode.

Types

type Resolver

type Resolver struct {
	App string
}

Resolver resolves an app's config file path from the standard precedence. App is the lowercase CLI name, e.g. "heraut" → HERAUT_FILE, .config/heraut.yml, .heraut.yml.

func (Resolver) InitDest

func (r Resolver) InitDest() string

InitDest returns where a new config should be written: .config/<app>.yml if a .config/ directory exists, else .<app>.yml.

func (Resolver) Label

func (r Resolver) Label(src Source) string

Label returns a human-readable description of a Source, for messages like "config loaded from X (from <label>)".

func (Resolver) Resolve

func (r Resolver) Resolve(explicit string) (string, Source)

Resolve returns the config path to use and the source that determined it:

  1. explicit (--config) if non-empty → FromFlag
  2. <APP>_FILE env var if set → FromEnv
  3. .config/<app>.yml if it exists → FromXDG
  4. .<app>.yml fallback → FromDefault

A leading "~" in the flag or env value is expanded via ExpandHome.

type Source

type Source int

Source identifies how a config file path was resolved.

const (
	FromFlag    Source = iota // explicit --config flag
	FromEnv                   // <APP>_FILE environment variable
	FromXDG                   // .config/<app>.yml (auto-discovered)
	FromDefault               // .<app>.yml (fallback)
)

type ValidationError

type ValidationError struct {
	Path    string
	Message string
	Hint    string
}

ValidationError describes a single semantic validation failure: the config Path that failed, a Message, and an optional remediation Hint.

func (ValidationError) Error

func (e ValidationError) Error() string

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is a list of ValidationError that implements error.

func (ValidationErrors) Error

func (ve ValidationErrors) Error() string

Jump to

Keyboard shortcuts

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