Documentation
¶
Index ¶
- func AddConfigFile(format, filename string)
- func AddConfigFrom(format string, in io.Reader) error
- func AddConfigMap(cfg map[string]interface{}) error
- func AllowEmptyEnv(allowEmptyEnv bool)
- func BindEnv(input ...string) error
- func Config() map[string]interface{}
- func Debug()
- func Get(key string) interface{}
- func LoadConfig() error
- func Marshal(out io.Writer) error
- func Reset(opts ...Option)
- func Set(key string, value interface{})
- func SetDefault(key string, value interface{})
- func SetEnvPrefix(in string)
- func Unmarshal(rawVal interface{}, opts ...DecoderConfigOption) error
- func WriteConfigTo(out io.Writer) error
- type ConfigLoader
- type ConfigMarshalError
- type ConfigParseError
- type ConfigSource
- type DecoderConfigOption
- type File
- type Hugorm
- func (h *Hugorm) AddConfigFile(format, filename string)
- func (h *Hugorm) AddConfigFrom(format string, in io.Reader) error
- func (h *Hugorm) AddConfigMap(cfg map[string]interface{}) error
- func (h *Hugorm) AllowEmptyEnv(allowEmptyEnv bool)
- func (h *Hugorm) BindEnv(input ...string) error
- func (h *Hugorm) Config() map[string]interface{}
- func (h *Hugorm) Debug()
- func (h *Hugorm) Get(key string) interface{}
- func (h *Hugorm) LoadConfig() error
- func (h *Hugorm) Marshal(out io.Writer) error
- func (h *Hugorm) Set(key string, value interface{})
- func (h *Hugorm) SetDefault(key string, value interface{})
- func (h *Hugorm) SetEnvPrefix(in string)
- func (h *Hugorm) Unmarshal(rawVal interface{}, opts ...DecoderConfigOption) error
- func (h *Hugorm) WriteConfigTo(out io.Writer) error
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddConfigFile ¶
func AddConfigFile(format, filename string)
func AddConfigFrom ¶
AddConfigFrom will parse the data in the provided io.Reader and append it to the config.
func AddConfigMap ¶
AddConfigMap appends the configuration from the map given as a constant config source
func AllowEmptyEnv ¶
func AllowEmptyEnv(allowEmptyEnv bool)
AllowEmptyEnv tells Hugorm to consider set, but empty environment variables as valid values instead of falling back. For backward compatibility reasons this is false by default.
func BindEnv ¶
BindEnv binds a Hugorm key to a ENV variable. ENV variables are case sensitive. If only a key is provided, it will use the env key matching the key, uppercased. If more arguments are provided, they will represent the env variable names that should bind to this key and will be taken in the specified order. EnvPrefix will be used when set when env name is not provided.
func Get ¶
func Get(key string) interface{}
Get can retrieve any value given the key to use. Get is case-insensitive for a key. Get has the behavior of returning the value associated with the first place from where it is set. Viper will check in the following order: override, flag, env, config file, key/value store, default
Get returns an interface. For a specific value use one of the Get____ methods.
func LoadConfig ¶
func LoadConfig() error
LoadConfig will discover and load the configuration file from disk and key/value stores, searching in one of the defined paths.
func Reset ¶
func Reset(opts ...Option)
Reset is intended for testing, will reset all to default settings. In the public interface for the viper package so applications can use it in their testing as well.
func Set ¶
func Set(key string, value interface{})
Set sets the value for the key in the override register. Set is case-insensitive for a key. Will be used instead of values obtained via flags, config file, ENV, default, or key/value store.
func SetDefault ¶
func SetDefault(key string, value interface{})
SetDefault sets the default value for this key. Default only used when no value is provided by the user via flag, config or ENV.
func SetEnvPrefix ¶
func SetEnvPrefix(in string)
SetEnvPrefix defines a prefix that ENVIRONMENT variables will use. E.g. if your prefix is "spf", the env registry will look for env variables that start with "SPF_".
func Unmarshal ¶
func Unmarshal(rawVal interface{}, opts ...DecoderConfigOption) error
Unmarshal unmarshals the config into a Struct. Make sure that the tags on the fields of the structure are properly set.
func WriteConfigTo ¶
WriteConfig writes the current configuration to a file.
Types ¶
type ConfigLoader ¶
type ConfigLoader interface {
ConfigSource
Load() error
}
ConfigLoader is a ConfigSource which needs explicit loading to refresh it's values
type ConfigMarshalError ¶
type ConfigMarshalError struct {
// contains filtered or unexported fields
}
ConfigMarshalError happens when failing to marshal the configuration.
func (ConfigMarshalError) Error ¶
func (e ConfigMarshalError) Error() string
Error returns the formatted configuration error.
type ConfigParseError ¶
type ConfigParseError struct {
// contains filtered or unexported fields
}
ConfigParseError denotes failing to parse configuration file.
func (ConfigParseError) Error ¶
func (pe ConfigParseError) Error() string
Error returns the formatted configuration error.
type ConfigSource ¶
type ConfigSource interface {
Values() map[string]interface{}
}
ConfigSource is a case sensitive recursive store of config key/value (values can be maps)
type DecoderConfigOption ¶
type DecoderConfigOption func(*mapstructure.DecoderConfig)
A DecoderConfigOption can be passed to hugorm.Unmarshal to configure mapstructure.DecoderConfig options
func DecodeHook ¶
func DecodeHook(hook mapstructure.DecodeHookFunc) DecoderConfigOption
DecodeHook returns a DecoderConfigOption which overrides the default DecoderConfig.DecodeHook value, the default is:
mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToTimeDurationHookFunc(),
mapstructure.StringToSliceHookFunc(","),
)
type Hugorm ¶
type Hugorm struct {
// contains filtered or unexported fields
}
Hugorm is a prioritized configuration registry. It maintains a set of configuration sources, fetches values to populate those, and provides them according to the source's priority. The priority of the sources is the following: 1. overrides (see the Set() function) 2. flags 3. env. variables 4. other config sources, - per default a file in a supported format 5. defaults (see the SetDefault() function)
Config sources can be hierarchical (like a JSON file), but each value still has a unique key in a flat keyspace. (using a key-delimiter to define it's path)
So - given a key-delimiter of "." the following will be true:
JSON config:
{
"foo" : {
"bar": "baz"
}
}
key "foo.bar" == "baz"
func (*Hugorm) AddConfigFile ¶
func (*Hugorm) AddConfigMap ¶
func (*Hugorm) AllowEmptyEnv ¶
func (*Hugorm) LoadConfig ¶
func (*Hugorm) SetDefault ¶
func (*Hugorm) SetEnvPrefix ¶
func (*Hugorm) Unmarshal ¶
func (h *Hugorm) Unmarshal(rawVal interface{}, opts ...DecoderConfigOption) error
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func CaseSensitive ¶
func ConfigFile ¶
func KeyDelimiter ¶
KeyDelimiter sets the delimiter used for determining key parts. By default it's value is ".".