Documentation
¶
Overview ¶
Package confmaker is application-level configuration for Go services. A library declares its config as a plain struct with `koanf` (file) and `env` (environment) tags; the application loads the file and fills each library's struct, so a library never reads files or the environment itself.
Two entry points build on this root package. confmaker/confx wires configuration into Uber Fx - it loads the file once and provides each library its filled, validated config by name. Load (below) decodes a whole file into a struct for services that do not use Fx.
Infrastructure libraries need only the dependency-free secret type (github.com/uchaloop/secret); importing this package or confx stays optional, for when a library wants more. The `koanf`/`env` tags a library declares are inert strings the app-level loader reads.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load reads the given TOML files in order and decodes the merged result into dst using the `koanf:"..."` struct tags. Later files override earlier ones, so a base + environment-overlay layout works by passing base first. With no paths, it reads config.toml from the current working directory.
Decoding is strict: an unknown key in the file (a typo, or a field that does not exist on dst) fails instead of being silently ignored. Durations are parsed from strings such as "30m"; weak type coercion is disabled, so a mistyped value fails rather than being guessed.
func Required ¶
Required returns the instance named name from a map of configured instances, or an error naming what is missing. kind labels the resource in the error, for example "postgres" or "kafka consumer". Use it to turn a required-but-absent named connection into a clear startup failure.
func ResolveSecret ¶
ResolveSecret reads a secret value from the named environment variable. It returns an error - naming only the variable, never the value - when the variable is unset or empty, so a missing secret fails the startup loudly without leaking anything into logs.
Types ¶
type Registry ¶
type Registry[T any] struct { // contains filtered or unexported fields }
Registry holds a set of named instances of the same type, for resources whose count is only known at runtime. Prefer confx (Fx-wired named instances) for the fixed, mandatory instances of a service; use a Registry only for genuinely dynamic ones.
func MakeRegistry ¶
MakeRegistry returns a Registry over items. The map is used as-is.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package confx wires configuration into Uber Fx.
|
Package confx wires configuration into Uber Fx. |
|
Package validate provides a small error accumulator so a Validate method can report every problem in one pass instead of failing on the first.
|
Package validate provides a small error accumulator so a Validate method can report every problem in one pass instead of failing on the first. |