Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load reads configuration using the given options, using it to populate a struct.
Configuration is first loaded from environment variables, then files, and finally Kubernetes mounts. The last loaded configuration value wins if any conflicts occur.
The struct should contains fields with "koanf" tags identifying the configuration key to assign. For example:
type LoggingConfig struct {
// reads "level" into the field
Level string `koanf:"level"`
}
The field type can be anything supported by mapstructure, or an implementation of encoding.TextUnmarshaler. If configuration keys contain ".", then nested structs must be used to access the value. For example:
type Config struct {
Log struct{
// reads "log.level" into the field
Level string `koanf:"level"`
} `koanf:"log"`
}
A default value can be set using a "default" struct tag with the desired value. For example:
type LoggingConfig struct {
Level string `koanf:"level" default:"info"`
}
A default-able field type can be anything supported by defaults, or an implementation of defaults.Setter, encoding.TextUnmarshaler, or encoding/json.Unmarshaler.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config provides loading of configuration values for a service.
type Options ¶
type Options struct {
// The prefix of environment variables to read configuration from. Matching environment
// variables have the prefix removed, are converted to lowercase and any underscores are
// replaced with ".". For example, "APP_LOG_LEVEL" with a prefix of "APP_" would become
// "log.level".
EnvPrefix string
// The file paths to read configuration from. Supported file formats and extensions are:
//
// - JSON: .json
// - YAML: .yml, .yaml
// - TOML: .toml
//
// The file content is read into a map where nested map keys are joined using ".". For example,
// a JSON file containing {"log":{"level":"info"}} would become "log.level".
Files []string
// The directories of Kubernetes pod mounts to read configuration from. The filenames of the
// mounted values become the configuration keys. For example, a configmap field of "log.level"
// can be accessed at the same name.
Mounts []string
}
Options provides the values to bootstrap configuration collection.