Documentation
¶
Overview ¶
Package termconfig loads layered configuration for terminull apps.
Precedence, low to high: Defaults, config files, environment, Overrides (parsed CLI flags, handed over by package app).
Files are searched in order and every existing file is layered, so project-local settings win over user-global ones:
- explicit --config path (missing file is an error)
- home dotfile: ~/.APPNAME.yaml
- user config dir: %APPDATA%/APPNAME/APPNAME.yaml, ~/.config/APPNAME/APPNAME.yaml, ~/Library/Application Support/...
- working directory: ./APPNAME.yaml then ./.APPNAME.yaml
Environment variables use APPNAME_ prefixes: APPNAME_DB_HOST becomes db.host. Numeric-looking and true/false values become typed.
Unknown keys fail loudly, but only at UnmarshalStrict time: typos in files or env surface as errors naming the key instead of silent zero values.
Index ¶
- type Config
- func (c *Config) All() map[string]any
- func (c *Config) Bool(path string) bool
- func (c *Config) Exists(path string) bool
- func (c *Config) Float64(path string) float64
- func (c *Config) Get(path string) any
- func (c *Config) Int(path string) int
- func (c *Config) String(path string) string
- func (c *Config) Strings(path string) []string
- func (c *Config) Unmarshal(target any) error
- func (c *Config) UnmarshalStrict(target any) error
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config wraps the layered koanf instance.
func (*Config) Unmarshal ¶
Unmarshal decodes into target with weak typing (env strings convert). Unknown keys are ignored; use UnmarshalStrict to reject them.
func (*Config) UnmarshalStrict ¶
UnmarshalStrict decodes like Unmarshal but fails naming any key that has no matching struct field, catching typos in files and env.
type Options ¶
type Options struct {
// AppName drives file names and the env prefix: "deploy" looks for
// deploy.yaml and reads DEPLOY_ variables.
AppName string
// ConfigFile is an explicit --config path. Missing file is an error.
ConfigFile string
// Defaults is the lowest-precedence layer.
Defaults map[string]any
// Overrides is the highest-precedence layer (parsed CLI flags).
Overrides map[string]any
// EnvPrefix overrides the derived UPPER(AppName)+"_" prefix.
EnvPrefix string
// Environ injects environment lines for tests; nil uses os.Environ.
Environ []string
// EnvironFunc injects an environ function; takes precedence over Environ.
EnvironFunc func() []string
}
Options tunes a Load call. Zero value loads nothing but empty defaults.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
koanf/confmap
Package confmap implements a koanf.Provider that takes nested and flat map[string]any config maps and provides them to koanf.
|
Package confmap implements a koanf.Provider that takes nested and flat map[string]any config maps and provides them to koanf. |
|
koanf/env
Package env implements a koanf.Provider that reads environment variables as conf maps.
|
Package env implements a koanf.Provider that reads environment variables as conf maps. |
|
koanf/file
Package file implements a koanf.Provider that reads raw bytes from files on disk to be used with a koanf.Parser to parse into conf maps.
|
Package file implements a koanf.Provider that reads raw bytes from files on disk to be used with a koanf.Parser to parse into conf maps. |
|
koanf/maps
Package maps provides reusable functions for manipulating nested map[string]interface{} maps are common unmarshal products from various serializers such as json, yaml etc.
|
Package maps provides reusable functions for manipulating nested map[string]interface{} maps are common unmarshal products from various serializers such as json, yaml etc. |
|
koanf/yaml
Package yaml implements a koanf.Parser that parses YAML bytes as conf maps.
|
Package yaml implements a koanf.Parser that parses YAML bytes as conf maps. |
|
mapstructure
Package mapstructure exposes functionality to convert one arbitrary Go type into another, typically to convert a map[string]any into a native Go structure.
|
Package mapstructure exposes functionality to convert one arbitrary Go type into another, typically to convert a map[string]any into a native Go structure. |
|
reflectwalk
reflectwalk is a package that allows you to "walk" complex structures similar to how you may "walk" a filesystem: visiting every element one by one and calling callback functions allowing you to handle and manipulate those elements.
|
reflectwalk is a package that allows you to "walk" complex structures similar to how you may "walk" a filesystem: visiting every element one by one and calling callback functions allowing you to handle and manipulate those elements. |