Documentation ¶
Overview ¶
Package config provides a standard interface to a configuration storage system.
With an example using spf13/viper and wrapping with a mutex to make it thread-safe.
Index ¶
- type Conf
- func NewViperConfD(project string, confdpath string, filename ...string) Conf
- func NewViperConfDFromViper(vcfg *viper.Viper, confdpath string, filename ...string) Conf
- func NewViperConfig(project string, filename ...string) Conf
- func NewViperConfigFromViper(vcfg *viper.Viper, filename ...string) Conf
- type ViperConf
- func (v *ViperConf) Get(key string) interface{}
- func (v *ViperConf) GetBool(key string) bool
- func (v *ViperConf) GetDuration(key string) time.Duration
- func (v *ViperConf) GetFloat64(key string) float64
- func (v *ViperConf) GetInt(key string) int
- func (v *ViperConf) GetIntSlice(key string) []int
- func (v *ViperConf) GetString(key string) string
- func (v *ViperConf) GetStringSlice(key string) []string
- func (v *ViperConf) Save() error
- func (v *ViperConf) Set(key string, value interface{})
- func (v *ViperConf) SetBool(key string, value bool)
- func (v *ViperConf) SetDefault(key string, value interface{})
- func (v *ViperConf) SetDuration(key string, value time.Duration)
- func (v *ViperConf) SetFloat64(key string, value float64)
- func (v *ViperConf) SetInt(key string, value int)
- func (v *ViperConf) SetIntSlice(key string, value []int)
- func (v *ViperConf) SetString(key string, value string)
- func (v *ViperConf) SetStringSlice(key string, value []string)
- func (v *ViperConf) Write(out io.Writer) error
- func (v *ViperConf) ZapConfig() zap.Config
- type ViperConfD
- func (v *ViperConfD) AllSettings() map[string]interface{}
- func (v *ViperConfD) Get(key string) interface{}
- func (v *ViperConfD) GetBool(key string) bool
- func (v *ViperConfD) GetDuration(key string) time.Duration
- func (v *ViperConfD) GetFloat64(key string) float64
- func (v *ViperConfD) GetInt(key string) int
- func (v *ViperConfD) GetIntSlice(key string) []int
- func (v *ViperConfD) GetString(key string) string
- func (v *ViperConfD) GetStringSlice(key string) []string
- func (v *ViperConfD) Save() error
- func (v *ViperConfD) Set(key string, value interface{})
- func (v *ViperConfD) SetBool(key string, value bool)
- func (v *ViperConfD) SetDefault(key string, value interface{})
- func (v *ViperConfD) SetDuration(key string, value time.Duration)
- func (v *ViperConfD) SetFloat64(key string, value float64)
- func (v *ViperConfD) SetInt(key string, value int)
- func (v *ViperConfD) SetIntSlice(key string, value []int)
- func (v *ViperConfD) SetString(key string, value string)
- func (v *ViperConfD) SetStringSlice(key string, value []string)
- func (v *ViperConfD) Write(out io.Writer) error
- func (v *ViperConfD) ZapConfig() zap.Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conf ¶
type Conf interface { Get(key string) interface{} GetBool(key string) bool GetDuration(key string) time.Duration GetFloat64(key string) float64 GetInt(key string) int GetIntSlice(key string) []int GetString(key string) string GetStringSlice(key string) []string Set(key string, value interface{}) SetBool(key string, value bool) SetDuration(key string, value time.Duration) SetFloat64(key string, value float64) SetInt(key string, value int) SetIntSlice(key string, value []int) SetString(key string, value string) SetStringSlice(key string, value []string) ZapConfig() zap.Config Save() error }
Conf is the default configuration object interface.
func NewViperConfD ¶ added in v0.5.0
NewViperConfD returns a Conf compatible ViperConfD object.
func NewViperConfDFromViper ¶ added in v0.5.0
NewViperConfDFromViper returns a Conf compatible ViperConfD object copied from the system viper.Viper.
func NewViperConfig ¶
NewViperConfig returns a Conf compatible ViperConf object.
type ViperConf ¶
type ViperConf struct {
// contains filtered or unexported fields
}
ViperConf is a Conf compatible Viper configuration object.
func (*ViperConf) Get ¶
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 (*ViperConf) GetDuration ¶
GetDuration returns the value associated with the key as a duration.
func (*ViperConf) GetFloat64 ¶
GetFloat64 returns the value associated with the key as a float64.
func (*ViperConf) GetIntSlice ¶
GetIntSlice returns the value associated with the key as a slice of ints.
func (*ViperConf) GetStringSlice ¶
GetStringSlice returns the value associated with the key as a slice of strings.
func (*ViperConf) SetDefault ¶ added in v0.3.0
SetDefault sets the default value for this key. SetDefault is case-insensitive for a key. Default only used when no value is provided by the user via flag, config or ENV.
func (*ViperConf) SetDuration ¶
SetDuration sets the value for the key in the viper object.
func (*ViperConf) SetFloat64 ¶
SetFloat64 sets the value for the key in the viper object.
func (*ViperConf) SetIntSlice ¶
SetIntSlice sets the value for the key in the viper object.
func (*ViperConf) SetStringSlice ¶
SetStringSlice sets the value for the key in the viper object.
type ViperConfD ¶ added in v0.5.0
type ViperConfD struct {
// contains filtered or unexported fields
}
ViperConfD is a Conf compatible Viper configuration object.
func (*ViperConfD) AllSettings ¶ added in v0.5.0
func (v *ViperConfD) AllSettings() map[string]interface{}
AllSettings merges all settings and returns them as a map[string]interface{}.
func (*ViperConfD) Get ¶ added in v0.5.0
func (v *ViperConfD) 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 (*ViperConfD) GetBool ¶ added in v0.5.0
func (v *ViperConfD) GetBool(key string) bool
GetBool returns the value associated with the key as a boolean.
func (*ViperConfD) GetDuration ¶ added in v0.5.0
func (v *ViperConfD) GetDuration(key string) time.Duration
GetDuration returns the value associated with the key as a duration.
func (*ViperConfD) GetFloat64 ¶ added in v0.5.0
func (v *ViperConfD) GetFloat64(key string) float64
GetFloat64 returns the value associated with the key as a float64.
func (*ViperConfD) GetInt ¶ added in v0.5.0
func (v *ViperConfD) GetInt(key string) int
GetInt returns the value associated with the key as an int.
func (*ViperConfD) GetIntSlice ¶ added in v0.5.0
func (v *ViperConfD) GetIntSlice(key string) []int
GetIntSlice returns the value associated with the key as a slice of ints.
func (*ViperConfD) GetString ¶ added in v0.5.0
func (v *ViperConfD) GetString(key string) string
GetString returns the value associated with the key as a string.
func (*ViperConfD) GetStringSlice ¶ added in v0.5.0
func (v *ViperConfD) GetStringSlice(key string) []string
GetStringSlice returns the value associated with the key as a slice of strings.
func (*ViperConfD) Save ¶ added in v0.5.0
func (v *ViperConfD) Save() error
Save writes the config to the file system.
func (*ViperConfD) Set ¶ added in v0.5.0
func (v *ViperConfD) Set(key string, value interface{})
Set sets the value for the key in the viper object.
func (*ViperConfD) SetBool ¶ added in v0.5.0
func (v *ViperConfD) SetBool(key string, value bool)
SetBool sets the value for the key in the viper object.
func (*ViperConfD) SetDefault ¶ added in v0.5.0
func (v *ViperConfD) SetDefault(key string, value interface{})
SetDefault sets the default value for this key. SetDefault is case-insensitive for a key. Default only used when no value is provided by the user via flag, config or ENV.
func (*ViperConfD) SetDuration ¶ added in v0.5.0
func (v *ViperConfD) SetDuration(key string, value time.Duration)
SetDuration sets the value for the key in the viper object.
func (*ViperConfD) SetFloat64 ¶ added in v0.5.0
func (v *ViperConfD) SetFloat64(key string, value float64)
SetFloat64 sets the value for the key in the viper object.
func (*ViperConfD) SetInt ¶ added in v0.5.0
func (v *ViperConfD) SetInt(key string, value int)
SetInt sets the value for the key in the viper object.
func (*ViperConfD) SetIntSlice ¶ added in v0.5.0
func (v *ViperConfD) SetIntSlice(key string, value []int)
SetIntSlice sets the value for the key in the viper object.
func (*ViperConfD) SetString ¶ added in v0.5.0
func (v *ViperConfD) SetString(key string, value string)
SetString sets the value for the key in the viper object.
func (*ViperConfD) SetStringSlice ¶ added in v0.5.0
func (v *ViperConfD) SetStringSlice(key string, value []string)
SetStringSlice sets the value for the key in the viper object.
func (*ViperConfD) ZapConfig ¶ added in v0.5.0
func (v *ViperConfD) ZapConfig() zap.Config
ZapConfig returns a zap logger configuration derived from settings in the viper config.