Documentation
¶
Overview ¶
Package deafadder wraps koanf.Koanf configuration data objects, adding convenience accessor functions for pflag configuration data types.
Suppose you have developed a service or CLI tool using cobra and pflag to parse and handle CLI flags. Sweet and easy. Next, you want to support further configuration data sources, such as configuration files, opting for the koanf module(s). This assumes that in your service/CLI tool code base you are using the pflag.FlagSet flag value accessor functions, and not directly accessing the underlying flag values directly.
Here, the deafadder module comes in: in order to make this upgrade as simple and painless as possible without having to throw away all the pflag-related code, you basically just swap in the pflag value-compatible accessor code from the DeafAdder object, which is a simple wrapper for koanf.Koanf objects.
# before
var cmd *cobra.Command
addr, err := cmd.PersistentFlags().GetIP("addr")
# after
var k *koadnf.Koanf
d := deadadder.New(k)
addr, err := d.GetIP("addr")
What's a Deaf Adder? ¶
The name “deafadder” (“anguis fragilis sensu stricto”, better known as “slowworm”) is a pun on the Go cobra and viper modules: it refers to a species of legless lizard native to western Eurasia.
Technical Note ¶
Under its hood (or rather, skin) this package leverages the conversion functions implemented in the pflag package, inheriting its behavior but also some quirks. For instance, DeafAdder.GetIP currently does not report any errors in case of invalid textual IP addresses.
Index ¶
- type DeafAdder
- func (d *DeafAdder) GetBool(path string) (v bool, err error)
- func (d *DeafAdder) GetBytesBase64(path string) (v []byte, err error)
- func (d *DeafAdder) GetBytesHex(path string) (v []byte, err error)
- func (d *DeafAdder) GetCount(path string) (v int, err error)
- func (d *DeafAdder) GetDuration(path string) (v time.Duration, err error)
- func (d *DeafAdder) GetDurationSlice(path string) (v []time.Duration, err error)
- func (d *DeafAdder) GetFloat32(path string) (v float32, err error)
- func (d *DeafAdder) GetFloat32Slice(path string) (v []float32, err error)
- func (d *DeafAdder) GetFloat64(path string) (v float64, err error)
- func (d *DeafAdder) GetFloat64Slice(path string) (v []float64, err error)
- func (d *DeafAdder) GetIP(path string) (v net.IP, err error)
- func (d *DeafAdder) GetIPNet(path string) (v net.IPNet, err error)
- func (d *DeafAdder) GetIPNetSlice(path string) (v []net.IPNet, err error)
- func (d *DeafAdder) GetIPSlice(path string) (v []net.IP, err error)
- func (d *DeafAdder) GetInt(path string) (v int, err error)
- func (d *DeafAdder) GetInt8(path string) (v int8, err error)
- func (d *DeafAdder) GetInt16(path string) (v int16, err error)
- func (d *DeafAdder) GetInt32(path string) (v int32, err error)
- func (d *DeafAdder) GetInt32Slice(path string) (v []int32, err error)
- func (d *DeafAdder) GetInt64(path string) (v int64, err error)
- func (d *DeafAdder) GetInt64Slice(path string) (v []int64, err error)
- func (d *DeafAdder) GetIntSlice(path string) (v []int, err error)
- func (d *DeafAdder) GetString(path string) (v string, err error)
- func (d *DeafAdder) GetStringArray(path string) (v []string, err error)
- func (d *DeafAdder) GetStringSlice(path string) (v []string, err error)
- func (d *DeafAdder) GetUint(path string) (v uint, err error)
- func (d *DeafAdder) GetUint8(path string) (v uint8, err error)
- func (d *DeafAdder) GetUint16(path string) (v uint16, err error)
- func (d *DeafAdder) GetUint32(path string) (v uint32, err error)
- func (d *DeafAdder) GetUint64(path string) (v uint64, err error)
- func (d *DeafAdder) GetUintSlice(path string) (v []uint, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeafAdder ¶
DeafAdder (“anguis fragilis sensu stricto”, better known as “slowworm”) wraps a koanf.Koanf configuration data object. On top, DeafAdder objects provide convenience accessor functions for pflag-likeo configuration data types.
func New ¶
New returns a new DeafAdder object, wrapping the passed koanf.Koanf configuration data object.
func (*DeafAdder) GetBool ¶
GetBool returns the bool value of a configuration setting with the given name.
func (*DeafAdder) GetBytesBase64 ¶
GetBytesBase64 returns the []byte value of a configuration setting with the given name.
func (*DeafAdder) GetBytesHex ¶
GetBytesHex returns the []byte value of a configuration setting with the given name.
func (*DeafAdder) GetCount ¶
GetCount returns the int value of a configuration setting with the given name.
func (*DeafAdder) GetDuration ¶
GetDuration returns the duration value of a configuration setting with the given name.
func (*DeafAdder) GetDurationSlice ¶
GetDurationSlice returns the []time.Duration value of a configuration setting with the given name.
func (*DeafAdder) GetFloat32 ¶
GetFloat32 returns the float32 value of a configuration setting with the given name.
func (*DeafAdder) GetFloat32Slice ¶
GetFloat32Slice returns the []float32 value of a configuration setting with the given name.
func (*DeafAdder) GetFloat64 ¶
GetFloat64 returns the float64 value of a configuration setting with the given name.
func (*DeafAdder) GetFloat64Slice ¶
GetFloat64Slice returns the []float64 value of a configuration setting with the given name.
func (*DeafAdder) GetIP ¶
GetIP returns the net.IP value of a configuration setting with the given name.
func (*DeafAdder) GetIPNet ¶
GetIPNet returns the net.IPNet value of a configuration setting with the given name.
func (*DeafAdder) GetIPNetSlice ¶
GetIPNetSlice returns the []net.IPNet value of a configuration setting with the given name.
func (*DeafAdder) GetIPSlice ¶
GetIPSlice returns the []net.IP value of a configuration setting with the given name.
func (*DeafAdder) GetInt ¶
GetInt returns the int value of a configuration setting with the given name.
func (*DeafAdder) GetInt8 ¶
GetInt8 returns the int8 value of a configuration setting with the given name.
func (*DeafAdder) GetInt16 ¶
GetInt16 returns the int16 value of a configuration setting with the given name.
func (*DeafAdder) GetInt32 ¶
GetInt32 returns the int32 value of a configuration setting with the given name.
func (*DeafAdder) GetInt32Slice ¶
GetInt32Slice returns the []int32 value of a configuration setting with the given name.
func (*DeafAdder) GetInt64 ¶
GetInt64 returns the int64 value of a configuration setting with the given name.
func (*DeafAdder) GetInt64Slice ¶
GetInt64Slice returns the []int64 value of a configuration setting with the given name.
func (*DeafAdder) GetIntSlice ¶
GetIntSlice returns the []int value of a configuration setting with the given name.
func (*DeafAdder) GetString ¶
GetString returns the string value of a configuration setting with the given name.
func (*DeafAdder) GetStringArray ¶
GetStringArray returns the []string value of a configuration setting with the given name.
func (*DeafAdder) GetStringSlice ¶
GetStringSlice returns the []string value of a configuration setting with the given name.
func (*DeafAdder) GetUint ¶
GetUint returns the uint value of a configuration setting with the given name.
func (*DeafAdder) GetUint8 ¶
GetUint8 returns the uint8 value of a configuration setting with the given name.
func (*DeafAdder) GetUint16 ¶
GetUint16 returns the uint16 value of a configuration setting with the given name.
func (*DeafAdder) GetUint32 ¶
GetUint32 returns the uint32 value of a configuration setting with the given name.