Documentation
¶
Overview ¶
github.com/usvc/go-config is a package to manage configuration values in libraries/applications.
Defining a configuration map:
var conf = config.Map{ "bool_key": &config.Bool{}, "float_key": &config.Float{}, "int_key": &config.Int{}, "int_slice_key": &config.IntSlice{}, "string_key": &config.String{}, "uint_key": &config.Uint{}, "uint_slice_key": &config.UintSlice{}, }
Loading environment variables (assuming conf is defined):
conf.LoadFromEnvironment()
Applying to an instance of cobra.Command:
command := cobra.Command{ ... } conf.ApplyToCobra(&command)
Applying to an instance of cobra.Command persistently:
command := cobra.Command{ ... } conf.ApplyToCobraPersistent(&command)
Index ¶
- type Bool
- func (s *Bool) ApplyToFlagSet(name string, flags *pflag.FlagSet)
- func (s *Bool) GetDefault() interface{}
- func (s *Bool) GetShorthand() string
- func (s *Bool) GetUsage() string
- func (s *Bool) GetValue() interface{}
- func (s *Bool) GetValuePointer() interface{}
- func (s *Bool) SetValue(value interface{})
- type Config
- type Float
- func (s *Float) ApplyToFlagSet(name string, flags *pflag.FlagSet)
- func (s *Float) GetDefault() interface{}
- func (s *Float) GetShorthand() string
- func (s *Float) GetUsage() string
- func (s *Float) GetValue() interface{}
- func (s *Float) GetValuePointer() interface{}
- func (s *Float) SetValue(value interface{})
- type Int
- type IntSlice
- func (s *IntSlice) ApplyToFlagSet(name string, flags *pflag.FlagSet)
- func (s *IntSlice) GetDefault() interface{}
- func (s *IntSlice) GetShorthand() string
- func (s *IntSlice) GetUsage() string
- func (s *IntSlice) GetValue() interface{}
- func (s *IntSlice) GetValuePointer() interface{}
- func (s *IntSlice) SetValue(value interface{})
- type Map
- func (m *Map) ApplyToCobra(command *cobra.Command)
- func (m *Map) ApplyToCobraPersistent(command *cobra.Command)
- func (m *Map) ApplyToFlagSet(flags *pflag.FlagSet)
- func (m Map) Get(id string) interface{}
- func (m Map) GetBool(id string) bool
- func (m Map) GetFloat(id string) float64
- func (m Map) GetInt(id string) int
- func (m Map) GetIntSlice(id string) []int
- func (m Map) GetString(id string) string
- func (m Map) GetStringSlice(id string) []string
- func (m Map) GetUint(id string) uint
- func (m Map) GetUintSlice(id string) []uint
- func (m *Map) LoadFromEnvironment()
- func (m Map) Reset() error
- type String
- func (s *String) ApplyToFlagSet(name string, flags *pflag.FlagSet)
- func (s *String) GetDefault() interface{}
- func (s *String) GetShorthand() string
- func (s *String) GetUsage() string
- func (s *String) GetValue() interface{}
- func (s *String) GetValuePointer() interface{}
- func (s *String) SetValue(value interface{})
- type StringSlice
- func (s *StringSlice) ApplyToFlagSet(name string, flags *pflag.FlagSet)
- func (s *StringSlice) GetDefault() interface{}
- func (s *StringSlice) GetShorthand() string
- func (s *StringSlice) GetUsage() string
- func (s *StringSlice) GetValue() interface{}
- func (s *StringSlice) GetValuePointer() interface{}
- func (s *StringSlice) SetValue(value interface{})
- type Uint
- func (s *Uint) ApplyToFlagSet(name string, flags *pflag.FlagSet)
- func (s *Uint) GetDefault() interface{}
- func (s *Uint) GetShorthand() string
- func (s *Uint) GetUsage() string
- func (s *Uint) GetValue() interface{}
- func (s *Uint) GetValuePointer() interface{}
- func (s *Uint) SetValue(value interface{})
- type UintSlice
- func (s *UintSlice) ApplyToFlagSet(name string, flags *pflag.FlagSet)
- func (s *UintSlice) GetDefault() interface{}
- func (s *UintSlice) GetShorthand() string
- func (s *UintSlice) GetUsage() string
- func (s *UintSlice) GetValue() interface{}
- func (s *UintSlice) GetValuePointer() interface{}
- func (s *UintSlice) SetValue(value interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
Bool represents a configuration which should be interpreted as a boolean-typed value
func (*Bool) ApplyToFlagSet ¶
ApplyToFlagSet applies the configuration to a provided flag set
func (*Bool) GetDefault ¶
func (s *Bool) GetDefault() interface{}
GetDefault retrieves the default value of this configuration
func (*Bool) GetShorthand ¶
GetShorthand retrieves the short form of the flag if available
func (*Bool) GetValue ¶
func (s *Bool) GetValue() interface{}
GetValue returns the value of this configuration
func (*Bool) GetValuePointer ¶
func (s *Bool) GetValuePointer() interface{}
GetValuePointer returns a pointer that points to the instance of the configured value
type Config ¶
type Config interface { ApplyToFlagSet(name string, flagset *pflag.FlagSet) GetDefault() interface{} GetShorthand() string GetUsage() string GetValue() interface{} GetValuePointer() interface{} SetValue(value interface{}) }
Config defines an interface that all configuration keys should implement
type Float ¶
Float stores the configuration details for a floating point value
func (*Float) ApplyToFlagSet ¶
ApplyToFlagSet applies the configuration to a provided flag set
func (*Float) GetDefault ¶
func (s *Float) GetDefault() interface{}
GetDefault retrieves the default value of this configuration
func (*Float) GetShorthand ¶
GetShorthand retrieves the short form of the flag if available
func (*Float) GetValue ¶
func (s *Float) GetValue() interface{}
GetValue returns the value of this configuration
func (*Float) GetValuePointer ¶
func (s *Float) GetValuePointer() interface{}
GetValuePointer returns a pointer that points to the instance of the configured value
type Int ¶
Int represents a configuration which should be interpreted as a signed integer
func (*Int) ApplyToFlagSet ¶
ApplyToFlagSet applies the configuration to a provided flag set
func (*Int) GetDefault ¶
func (s *Int) GetDefault() interface{}
GetDefault retrieves the default value of this configuration
func (*Int) GetShorthand ¶
GetShorthand retrieves the short form of the flag if available
func (*Int) GetValue ¶
func (s *Int) GetValue() interface{}
GetValue returns the value of this configuration
func (*Int) GetValuePointer ¶
func (s *Int) GetValuePointer() interface{}
GetValuePointer returns a pointer that points to the instance of the configured value
type IntSlice ¶
IntSlice represents a configuration which should be interpreted as a slice of signed integers
func (*IntSlice) ApplyToFlagSet ¶
ApplyToFlagSet applies the configuration to a provided flag set
func (*IntSlice) GetDefault ¶
func (s *IntSlice) GetDefault() interface{}
GetDefault retrieves the default value of this configuration
func (*IntSlice) GetShorthand ¶
GetShorthand retrieves the short form of the flag if available
func (*IntSlice) GetValue ¶
func (s *IntSlice) GetValue() interface{}
GetValue returns the value of this configuration
func (*IntSlice) GetValuePointer ¶
func (s *IntSlice) GetValuePointer() interface{}
GetValuePointer returns a pointer that points to the instance of the configured value
type Map ¶
Map stores a map of configurations identifed by a string key
func (*Map) ApplyToCobra ¶
ApplyToCobra applies the configuration stored in the instance of Map to a cobra.Command instance as flags (cannot be accessed by child commands)
func (*Map) ApplyToCobraPersistent ¶ added in v0.1.20
ApplyToCobraPersistent applies the configuration stored in the instance of Map to a cobra.Command instance as persistent flags (can be accessed by child commands)
func (*Map) ApplyToFlagSet ¶ added in v0.1.20
ApplyToFlagSet applies the configuration stored in the instance of Map to a provided set of flags
func (Map) Get ¶
Get retrieves the value of the configuration identified by the key :id as an `interface{}` type
func (Map) GetBool ¶
GetBool retrieves the value of the configuration identified by the key :id as a boolean type
func (Map) GetFloat ¶
GetFloat retrieves the value of the configuration identified by the key :id as a floating point type
func (Map) GetInt ¶
GetInt retrieves the value of the configuration identified by the key :id as an integer type
func (Map) GetIntSlice ¶
GetIntSlice retrieves the value of the configuration identified by the key :id as an integer slice type
func (Map) GetString ¶
GetString retrieves the value of the configuration identified by the key :id as a string type
func (Map) GetStringSlice ¶
GetStringSlice retrieves the value of the configuration identified by the key :id as a string slice type
func (Map) GetUint ¶
GetUint retrieves the value of the configuration identified by the key :id as an unsigned integer type
func (Map) GetUintSlice ¶
GetUintSlice retrieves the value of the configuration identified by the key :id as an unsigned intger slice type
func (*Map) LoadFromEnvironment ¶
func (m *Map) LoadFromEnvironment()
LoadFromEnvironment loads the configuration from pre-defined environment variables
type String ¶
String represents a configuration which should be interpreted as a string-typed value
func (*String) ApplyToFlagSet ¶
ApplyToFlagSet applies the configuration to a provided flag set
func (*String) GetDefault ¶
func (s *String) GetDefault() interface{}
GetDefault retrieves the default value of this configuration
func (*String) GetShorthand ¶
GetShorthand retrieves the short form of the flag if available
func (*String) GetValue ¶
func (s *String) GetValue() interface{}
GetValue returns the value of this configuration
func (*String) GetValuePointer ¶
func (s *String) GetValuePointer() interface{}
GetValuePointer returns a pointer that points to the instance of the configured value
type StringSlice ¶
StringSlice represents a configuration which should be represented as a slice of strings
func (*StringSlice) ApplyToFlagSet ¶
func (s *StringSlice) ApplyToFlagSet(name string, flags *pflag.FlagSet)
// ApplyToFlagSet applies the configuration to a provided flag set
func (*StringSlice) GetDefault ¶
func (s *StringSlice) GetDefault() interface{}
GetDefault retrieves the default value of this configuration
func (*StringSlice) GetShorthand ¶
func (s *StringSlice) GetShorthand() string
GetShorthand retrieves the short form of the flag if available
func (*StringSlice) GetUsage ¶
func (s *StringSlice) GetUsage() string
GetUsage retrieves the usage string for this configuration
func (*StringSlice) GetValue ¶
func (s *StringSlice) GetValue() interface{}
GetValue returns the value of this configuration
func (*StringSlice) GetValuePointer ¶
func (s *StringSlice) GetValuePointer() interface{}
GetValuePointer returns a pointer that points to the instance of the configured value
func (*StringSlice) SetValue ¶
func (s *StringSlice) SetValue(value interface{})
SetValue sets the value of this configuration
type Uint ¶
Uint represents a configuration which should be interpreted as an unsigned integer
func (*Uint) ApplyToFlagSet ¶
ApplyToFlagSet applies the configuration to a provided flag set
func (*Uint) GetDefault ¶
func (s *Uint) GetDefault() interface{}
GetDefault retrieves the default value of this configuration
func (*Uint) GetShorthand ¶
GetShorthand retrieves the short form of the flag if available
func (*Uint) GetValue ¶
func (s *Uint) GetValue() interface{}
GetValue returns the value of this configuration
func (*Uint) GetValuePointer ¶
func (s *Uint) GetValuePointer() interface{}
GetValuePointer returns a pointer that points to the instance of the configured value
type UintSlice ¶
UintSlice represents a configuration which should be interpreted as a slice of unsigned integers
func (*UintSlice) ApplyToFlagSet ¶
ApplyToFlagSet applies the configuration to a provided flag set
func (*UintSlice) GetDefault ¶
func (s *UintSlice) GetDefault() interface{}
GetDefault retrieves the default value of this configuration
func (*UintSlice) GetShorthand ¶
GetShorthand retrieves the short form of the flag if available
func (*UintSlice) GetValue ¶
func (s *UintSlice) GetValue() interface{}
GetValue returns the value of this configuration
func (*UintSlice) GetValuePointer ¶
func (s *UintSlice) GetValuePointer() interface{}
GetValuePointer returns a pointer that points to the instance of the configured value