config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package config provides typed configuration loading from YAML files with environment-variable overlay for the Krewire ecosystem.

Precedence is strictly: built-in zero values < file < environment. Later sources win.

Index

Constants

View Source
const DefaultPrefix = "APP"

DefaultPrefix is prepended to implicit environment keys derived from field names. Fields tagged `env:"KEY"` are always read from the exact key.

Variables

This section is empty.

Functions

func Load

func Load(path string, dst any) error

Load reads the YAML file at path and unmarshals it into dst (a non-nil pointer to a struct), binding values by `yaml` tag or lowercased field name. A missing file leaves dst at its zero value and returns nil; a malformed file returns a wrapped error naming the path.

func LoadOrDefault

func LoadOrDefault(path string, dst any) error

LoadOrDefault behaves like Load and is provided for tooling that tolerates an absent configuration file: a missing file yields the struct's zero value and never an error.

func Override

func Override(dst any, lookup func(string) (string, bool), opts ...Option) error

Override applies environment values on top of an already-loaded struct. A field tagged `env:"KEY"` is read from the exact key; an untagged field derives an implicit key from its yaml tag/name uppercased with `-` and `.` replaced by `_`, prefixed by DefaultPrefix (or the prefix from WithPrefix), joining nested struct segments with `_` (e.g. `Server.Addr` -> APP_SERVER_ADDR). Empty environment values are treated as unset. Slices and maps are not overlaid in this phase.

Types

type Option

type Option func(*options)

Option configures loading behavior.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix overrides DefaultPrefix used for implicit environment keys.

Jump to

Keyboard shortcuts

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