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/v2); 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. Values targeting exported secret.Value fields are ignored so a file can never populate them. Durations are parsed from strings such as "30m"; weak type coercion is disabled, so a mistyped value fails rather than being guessed.
func LoadDir ¶ added in v0.3.0
LoadDir resolves configuration files from dir using the confmaker directory convention and decodes their merged contents into dst.
ENVIRONMENT is required and accepts dev, stage, prod, or prd (an alias for prod). An optional common.toml is loaded first; the required canonical environment file (dev.toml, stage.toml, or prod.toml) is loaded second and overrides common values.
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. |
|
internal
|
|
|
dirconfig
Package dirconfig resolves the convention-based configuration files shared by confmaker and confmaker/confx.
|
Package dirconfig resolves the convention-based configuration files shared by confmaker and confmaker/confx. |
|
filedecode
Package filedecode contains decode hooks shared by confmaker's file loaders.
|
Package filedecode contains decode hooks shared by confmaker's file loaders. |
|
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. |