Documentation ¶
Index ¶
- Variables
- func BindParameters(pointerToStruct interface{}, optionalNamespace ...string)
- func UpdateBoundParameters(configuration *Configuration)
- type BoundParameter
- type Configuration
- func (c *Configuration) All() map[string]interface{}
- func (c *Configuration) Bool(path string) bool
- func (c *Configuration) BoolMap(path string) map[string]bool
- func (c *Configuration) Bools(path string) []bool
- func (c *Configuration) Bytes(path string) []byte
- func (c *Configuration) Duration(path string) time.Duration
- func (c *Configuration) Exists(path string) bool
- func (c *Configuration) Float64(path string) float64
- func (c *Configuration) Float64Map(path string) map[string]float64
- func (c *Configuration) Float64s(path string) []float64
- func (c *Configuration) Get(path string) interface{}
- func (c *Configuration) Int(path string) int
- func (c *Configuration) Int64(path string) int64
- func (c *Configuration) Int64Map(path string) map[string]int64
- func (c *Configuration) Int64s(path string) []int64
- func (c *Configuration) IntMap(path string) map[string]int
- func (c *Configuration) Ints(path string) []int
- func (c *Configuration) LoadEnvironmentVars(prefix string) error
- func (c *Configuration) LoadFile(filePath string) error
- func (c *Configuration) LoadFlagSet(flagSet *flag.FlagSet) error
- func (c *Configuration) MapKeys(path string) []string
- func (c *Configuration) Print(ignoreSettingsAtPrint ...[]string)
- func (c *Configuration) Set(path string, value interface{}, parser ...koanf.Parser) error
- func (c *Configuration) SetDefault(path string, value interface{}, parser ...koanf.Parser) error
- func (c *Configuration) SetDefaultStruct(path string, value interface{}, fieldTag string, parser ...koanf.Parser) error
- func (c *Configuration) SetStruct(path string, value interface{}, fieldTag string, parser ...koanf.Parser) error
- func (c *Configuration) StoreFile(filePath string, ignoreSettingsAtStore ...[]string) error
- func (c *Configuration) String(path string) string
- func (c *Configuration) StringMap(path string) map[string]string
- func (c *Configuration) Strings(path string) []string
- func (c *Configuration) StringsMap(path string) map[string][]string
- func (c *Configuration) Time(path, layout string) time.Time
- func (c *Configuration) Unmarshal(path string, o interface{}) error
- func (c *Configuration) UnmarshalWithConf(path string, o interface{}, uc koanf.UnmarshalConf) error
- type JSONLowerParser
- type YAMLLowerParser
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownConfigFormat is returned if the format of the config file is unknown. ErrUnknownConfigFormat = errors.New("unknown config file format") )
Functions ¶
func BindParameters ¶
func BindParameters(pointerToStruct interface{}, optionalNamespace ...string)
BindParameters is a utility function that allows to define and bind a set of parameters in a single step by using a struct as the registry and definition for the created configuration parameters. It parses the relevant information from the struct using reflection and optionally provided information in the tags of its fields.
The parameter names are determined by the names of the fields in the struct but they can be overridden by providing a name tag. The default value is determined by the value of the field in the struct but it can be overridden by providing a default tag. The usage information are determined by the usage tag of the field.
The method supports nested structs which get translates to parameter names in the following way: --level1.level2.level3.parameterName
The first level is determined by the package of struct but it can be overridden by providing an optional namespace parameter.
func UpdateBoundParameters ¶
func UpdateBoundParameters(configuration *Configuration)
UpdateBoundParameters updates parameters that were bound using the BindParameters method with the current values in the configuration.
Types ¶
type BoundParameter ¶
type BoundParameter struct {
// contains filtered or unexported fields
}
BoundParameter stores the pointer and the type of values that were bound using the BindParameters function.
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration holds config parameters from several sources (file, env vars, flags).
func (*Configuration) All ¶
func (c *Configuration) All() map[string]interface{}
All returns a map of all flattened key paths and their values. Note that it uses maps.Copy to create a copy that uses json.Marshal which changes the numeric types to float64.
func (*Configuration) Bool ¶
func (c *Configuration) Bool(path string) bool
Bool returns the bool value of a given key path or false if the path does not exist or if the value is not a valid bool representation. Accepted string representations of bool are the ones supported by strconv.ParseBool.
func (*Configuration) BoolMap ¶
func (c *Configuration) BoolMap(path string) map[string]bool
BoolMap returns the map[string]bool value of a given key path or an empty map[string]bool if the path does not exist or if the value is not a valid bool map.
func (*Configuration) Bools ¶
func (c *Configuration) Bools(path string) []bool
Bools returns the []bool slice value of a given key path or an empty []bool slice if the path does not exist or if the value is not a valid bool slice.
func (*Configuration) Bytes ¶
func (c *Configuration) Bytes(path string) []byte
Bytes returns the []byte value of a given key path or an empty []byte slice if the path does not exist or if the value is not a valid string.
func (*Configuration) Duration ¶
func (c *Configuration) Duration(path string) time.Duration
Duration returns the time.Duration value of a given key path assuming that the key contains a valid numeric value.
func (*Configuration) Exists ¶
func (c *Configuration) Exists(path string) bool
Exists returns true if the given key path exists in the conf map.
func (*Configuration) Float64 ¶
func (c *Configuration) Float64(path string) float64
Float64 returns the float64 value of a given key path or 0 if the path does not exist or if the value is not a valid float64.
func (*Configuration) Float64Map ¶
func (c *Configuration) Float64Map(path string) map[string]float64
Float64Map returns the map[string]float64 value of a given key path or an empty map[string]float64 if the path does not exist or if the value is not a valid float64 map.
func (*Configuration) Float64s ¶
func (c *Configuration) Float64s(path string) []float64
Float64s returns the []float64 slice value of a given key path or an empty []float64 slice if the path does not exist or if the value is not a valid float64 slice.
func (*Configuration) Get ¶
func (c *Configuration) Get(path string) interface{}
Get returns the raw, uncast interface{} value of a given key path in the config map. If the key path does not exist, nil is returned.
func (*Configuration) Int ¶
func (c *Configuration) Int(path string) int
Int returns the int value of a given key path or 0 if the path does not exist or if the value is not a valid int.
func (*Configuration) Int64 ¶
func (c *Configuration) Int64(path string) int64
Int64 returns the int64 value of a given key path or 0 if the path does not exist or if the value is not a valid int64.
func (*Configuration) Int64Map ¶
func (c *Configuration) Int64Map(path string) map[string]int64
Int64Map returns the map[string]int64 value of a given key path or an empty map[string]int64 if the path does not exist or if the value is not a valid int64 map.
func (*Configuration) Int64s ¶
func (c *Configuration) Int64s(path string) []int64
Int64s returns the []int64 slice value of a given key path or an empty []int64 slice if the path does not exist or if the value is not a valid int slice.
func (*Configuration) IntMap ¶
func (c *Configuration) IntMap(path string) map[string]int
IntMap returns the map[string]int value of a given key path or an empty map[string]int if the path does not exist or if the value is not a valid int map.
func (*Configuration) Ints ¶
func (c *Configuration) Ints(path string) []int
Ints returns the []int slice value of a given key path or an empty []int slice if the path does not exist or if the value is not a valid int slice.
func (*Configuration) LoadEnvironmentVars ¶
func (c *Configuration) LoadEnvironmentVars(prefix string) error
LoadEnvironmentVars loads parameters from env vars and merges them into the loaded config. The prefix is used to filter the env vars. Only existing keys will be overwritten, all other keys are ignored.
func (*Configuration) LoadFile ¶
func (c *Configuration) LoadFile(filePath string) error
LoadFile loads parameters from a JSON or YAML file and merges them into the loaded config. Existing keys will be overwritten.
func (*Configuration) LoadFlagSet ¶
func (c *Configuration) LoadFlagSet(flagSet *flag.FlagSet) error
LoadFlagSet loads parameters from a FlagSet (spf13/pflag lib) including default values and merges them into the loaded config. Existing keys will only be overwritten, if they were set via command line. If not given via command line, default values will only be used if they did not exist beforehand.
func (*Configuration) MapKeys ¶
func (c *Configuration) MapKeys(path string) []string
MapKeys returns a sorted string list of keys in a map addressed by the given path. If the path is not a map, an empty string slice is returned.
func (*Configuration) Print ¶
func (c *Configuration) Print(ignoreSettingsAtPrint ...[]string)
Print prints the actual configuration, ignoreSettingsAtPrint are not shown.
func (*Configuration) Set ¶
func (c *Configuration) Set(path string, value interface{}, parser ...koanf.Parser) error
Set sets the value for the key (case-insensitive).
func (*Configuration) SetDefault ¶
func (c *Configuration) SetDefault(path string, value interface{}, parser ...koanf.Parser) error
SetDefault sets the default value for the key (case-insensitive). Default is only applied if no value is provided via flag, file or env vars.
func (*Configuration) SetDefaultStruct ¶
func (c *Configuration) SetDefaultStruct(path string, value interface{}, fieldTag string, parser ...koanf.Parser) error
SetDefaultStruct sets the default value for the key (case-insensitive). Default is only applied if no value is provided via flag, file or env vars.
func (*Configuration) SetStruct ¶
func (c *Configuration) SetStruct(path string, value interface{}, fieldTag string, parser ...koanf.Parser) error
SetStruct sets the value of the struct for the key (case-insensitive).
func (*Configuration) StoreFile ¶
func (c *Configuration) StoreFile(filePath string, ignoreSettingsAtStore ...[]string) error
StoreFile stores the current config to a JSON or YAML file. ignoreSettingsAtStore will not be stored to the file.
func (*Configuration) String ¶
func (c *Configuration) String(path string) string
String returns the string value of a given key path or "" if the path does not exist or if the value is not a valid string.
func (*Configuration) StringMap ¶
func (c *Configuration) StringMap(path string) map[string]string
StringMap returns the map[string]string value of a given key path or an empty map[string]string if the path does not exist or if the value is not a valid string map.
func (*Configuration) Strings ¶
func (c *Configuration) Strings(path string) []string
Strings returns the []string slice value of a given key path or an empty []string slice if the path does not exist or if the value is not a valid string slice.
func (*Configuration) StringsMap ¶
func (c *Configuration) StringsMap(path string) map[string][]string
StringsMap returns the map[string][]string value of a given key path or an empty map[string][]string if the path does not exist or if the value is not a valid strings map.
func (*Configuration) Time ¶
func (c *Configuration) Time(path, layout string) time.Time
Time attempts to parse the value of a given key path and return time.Time representation. If the value is numeric, it is treated as a UNIX timestamp and if it's string, a parse is attempted with the given layout.
func (*Configuration) Unmarshal ¶
func (c *Configuration) Unmarshal(path string, o interface{}) error
Unmarshal unmarshals a given key path into the given struct using the mapstructure lib. If no path is specified, the whole map is unmarshaled. `koanf` is the struct field tag used to match field names. To customize, use UnmarshalWithConf(). It uses the mitchellh/mapstructure package.
func (*Configuration) UnmarshalWithConf ¶
func (c *Configuration) UnmarshalWithConf(path string, o interface{}, uc koanf.UnmarshalConf) error
UnmarshalWithConf is like Unmarshal but takes configuration params in UnmarshalConf. See mitchellh/mapstructure's DecoderConfig for advanced customization of the unmarshal behaviour.
type JSONLowerParser ¶
type JSONLowerParser struct {
// contains filtered or unexported fields
}
JSONLowerParser implements a JSON parser. all config keys are lower cased.
type YAMLLowerParser ¶
type YAMLLowerParser struct{}
YAMLLowerParser implements a YAML parser. all config keys are lower cased.