Documentation ¶
Index ¶
- type ConfigFileNotFoundError
- type Loader
- type LoaderOption
- func WithBindPFlags(pfs *pflag.FlagSet, cfg interface{}) LoaderOption
- func WithEnvKeyReplacer(old string, new string) LoaderOption
- func WithEnvPrefix(in string) LoaderOption
- func WithFile(file string) LoaderOption
- func WithName(in string) LoaderOption
- func WithPath(in string) LoaderOption
- func WithType(in string) LoaderOption
- func WithViper(in *viper.Viper) LoaderOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigFileNotFoundError ¶
type ConfigFileNotFoundError struct {
// contains filtered or unexported fields
}
ConfigFileNotFoundError is returned when the config file is not found Viper will load from env or defaults
func (ConfigFileNotFoundError) Error ¶
func (err ConfigFileNotFoundError) Error() string
func (*ConfigFileNotFoundError) Unwrap ¶
func (err *ConfigFileNotFoundError) Unwrap() error
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
func NewLoader ¶
func NewLoader(options ...LoaderOption) *Loader
NewLoader returns a config loader with given LoaderOption(s)
func (*Loader) Load ¶
Load loads configuration into the given mapstructure (https://github.com/mitchellh/mapstructure) from a config.yaml file and overrides with any values set in env variables
type LoaderOption ¶
type LoaderOption func(*Loader)
func WithBindPFlags ¶ added in v0.2.0
func WithBindPFlags(pfs *pflag.FlagSet, cfg interface{}) LoaderOption
WithBindPFlags binds viper to pflags based on the tags in the struct. Use tag `cmdx` to bind struct field to cli flag. e.g.
type Config struct { Host string `yaml:"host" cmdx:"host"` }
func WithEnvKeyReplacer ¶
func WithEnvKeyReplacer(old string, new string) LoaderOption
WithEnvKeyReplacer sets the `old` string to be replaced with the `new` string environmental variable to a key that does not match it.
func WithEnvPrefix ¶
func WithEnvPrefix(in string) LoaderOption
WithEnvPrefix sets the prefix for keys when checking for configs in environment variables. Internally concatenates with keys with `_` in between
func WithFile ¶
func WithFile(file string) LoaderOption
WithFile explicitly defines the path, name and extension of the config file
func WithName ¶
func WithName(in string) LoaderOption
WithName sets the file name of the config file without the extension
func WithPath ¶
func WithPath(in string) LoaderOption
WithPath adds config path to search the config file in, can be used multiple times to add multiple paths to search
func WithType ¶
func WithType(in string) LoaderOption
WithType sets the type of the configuration e.g. "json", "yaml", "hcl" Also used for the extension of the file
func WithViper ¶
func WithViper(in *viper.Viper) LoaderOption
WithViper sets the given viper instance for loading configs instead of the default configured one