Documentation ¶
Overview ¶
Package cfgloader provides common functionality to load configs. It's meant for loading configs from YAML and/or env vars. Don't use it for initializing configs with defaults.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load loads config into the given config value. The loading order is:
- The existing values in the given config.
- Unmarshaled yaml bytes
- Env vars
The values loaded later will overwrite previously loaded values.
The given config type must have the yaml tags to load from yaml bytes. It must have the env tag to load from env vars. E.g.
type Cfg struct { StrVal string `yaml:"str_val,omitempty" env:"STR_VAL,overwrite,default=foo"` NumVal int `yaml:"num_val,omitempty" env:"NUM_VAL,overwrite,default=1"` }
Types ¶
type Option ¶
type Option func(*options) *options
Option is the config loading option type.
func WithEnvPrefix ¶
WithEnvPrefix instructs the loader to load config from env vars with the given prefix.
func WithLookuper ¶
func WithLookuper(lookuper envconfig.Lookuper) Option
WithLookuper instructs the loader to use the giver lookuper to find config values.
type Validatable ¶
type Validatable interface {
Validate() error
}
Validatable is the interface to validate a config. In addition to validating inputs, [Validate] may optionally fill or mutate config values.