Documentation ¶
Overview ¶
config package provides a way to load configuration from a file and environment variables. To enable loading from environment variables, you need to set the build tag "viper_bind_struct" because of https://github.com/spf13/viper/pull/1429#issuecomment-1870976604
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load loads the configuration from the provided path or fallback path. Returns an error if the configuration cannot be loaded or unmarshalled into the provided struct.
You can provide a slice of fallback functions that will be used to get the configuration path if an empty path is provided. The first fallback function that returns a path is used. If no fallback functions are provided, the default fallback is used (~/.config/<binary-name>/config.yaml).
All environment variables with the scheme "<binary-name>_<field-name>(_<recursive-field-name>)" will be considered.
The configuration is unmarshalled into the provided struct. Its IsEmpty method is called to check if the loaded configuration is empty. Most of the time, you want to implement it like this:
func (c Config) IsEmpty() bool { return c == (Config{}) }
func SetBinaryName ¶
func SetBinaryName(name string)
SetBinaryName replaces the default binary name with the provided one. This function is not safe for concurrent use.