deafadder

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README

deafadder

PkgGoDev GitHub build and test Coverage Go Report Card

Package deafadder wraps Koanf configuration data objects, adding convenience accessor functions for pflag configuration data types.

Please refer to the module documentation for usage and details.

Tinkering

When tinkering with the deafadder source code base, the recommended way is a devcontainer environment. The devcontainer specified in this repository contains:

  • gocover command to run all tests with coverage, updating the README coverage badge automatically after successful runs.
  • Go package documentation is served in the background on port TCP/HTTP 6060 of the devcontainer.
  • go-mod-upgrade
  • goreportcard-cli.
  • pin-github-action for maintaining Github Actions.

deafadder is Copyright 2025 Harald Albrecht, and licensed under the Apache License, Version 2.0.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeafAdder

type DeafAdder struct {
	*koanf.Koanf
}

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

func New(k *koanf.Koanf) *DeafAdder

New returns a new DeafAdder object, wrapping the passed koanf.Koanf configuration data object.

func (*DeafAdder) GetBool

func (d *DeafAdder) GetBool(path string) (v bool, err error)

GetBool returns the bool value of a configuration setting with the given name.

func (*DeafAdder) GetBytesBase64

func (d *DeafAdder) GetBytesBase64(path string) (v []byte, err error)

GetBytesBase64 returns the []byte value of a configuration setting with the given name.

func (*DeafAdder) GetBytesHex

func (d *DeafAdder) GetBytesHex(path string) (v []byte, err error)

GetBytesHex returns the []byte value of a configuration setting with the given name.

func (*DeafAdder) GetCount

func (d *DeafAdder) GetCount(path string) (v int, err error)

GetCount returns the int value of a configuration setting with the given name.

func (*DeafAdder) GetDuration

func (d *DeafAdder) GetDuration(path string) (v time.Duration, err error)

GetDuration returns the duration value of a configuration setting with the given name.

func (*DeafAdder) GetDurationSlice

func (d *DeafAdder) GetDurationSlice(path string) (v []time.Duration, err error)

GetDurationSlice returns the []time.Duration value of a configuration setting with the given name.

func (*DeafAdder) GetFloat32

func (d *DeafAdder) GetFloat32(path string) (v float32, err error)

GetFloat32 returns the float32 value of a configuration setting with the given name.

func (*DeafAdder) GetFloat32Slice

func (d *DeafAdder) GetFloat32Slice(path string) (v []float32, err error)

GetFloat32Slice returns the []float32 value of a configuration setting with the given name.

func (*DeafAdder) GetFloat64

func (d *DeafAdder) GetFloat64(path string) (v float64, err error)

GetFloat64 returns the float64 value of a configuration setting with the given name.

func (*DeafAdder) GetFloat64Slice

func (d *DeafAdder) GetFloat64Slice(path string) (v []float64, err error)

GetFloat64Slice returns the []float64 value of a configuration setting with the given name.

func (*DeafAdder) GetIP

func (d *DeafAdder) GetIP(path string) (v net.IP, err error)

GetIP returns the net.IP value of a configuration setting with the given name.

func (*DeafAdder) GetIPNet

func (d *DeafAdder) GetIPNet(path string) (v net.IPNet, err error)

GetIPNet returns the net.IPNet value of a configuration setting with the given name.

func (*DeafAdder) GetIPNetSlice

func (d *DeafAdder) GetIPNetSlice(path string) (v []net.IPNet, err error)

GetIPNetSlice returns the []net.IPNet value of a configuration setting with the given name.

func (*DeafAdder) GetIPSlice

func (d *DeafAdder) GetIPSlice(path string) (v []net.IP, err error)

GetIPSlice returns the []net.IP value of a configuration setting with the given name.

func (*DeafAdder) GetInt

func (d *DeafAdder) GetInt(path string) (v int, err error)

GetInt returns the int value of a configuration setting with the given name.

func (*DeafAdder) GetInt8

func (d *DeafAdder) GetInt8(path string) (v int8, err error)

GetInt8 returns the int8 value of a configuration setting with the given name.

func (*DeafAdder) GetInt16

func (d *DeafAdder) GetInt16(path string) (v int16, err error)

GetInt16 returns the int16 value of a configuration setting with the given name.

func (*DeafAdder) GetInt32

func (d *DeafAdder) GetInt32(path string) (v int32, err error)

GetInt32 returns the int32 value of a configuration setting with the given name.

func (*DeafAdder) GetInt32Slice

func (d *DeafAdder) GetInt32Slice(path string) (v []int32, err error)

GetInt32Slice returns the []int32 value of a configuration setting with the given name.

func (*DeafAdder) GetInt64

func (d *DeafAdder) GetInt64(path string) (v int64, err error)

GetInt64 returns the int64 value of a configuration setting with the given name.

func (*DeafAdder) GetInt64Slice

func (d *DeafAdder) GetInt64Slice(path string) (v []int64, err error)

GetInt64Slice returns the []int64 value of a configuration setting with the given name.

func (*DeafAdder) GetIntSlice

func (d *DeafAdder) GetIntSlice(path string) (v []int, err error)

GetIntSlice returns the []int value of a configuration setting with the given name.

func (*DeafAdder) GetString

func (d *DeafAdder) GetString(path string) (v string, err error)

GetString returns the string value of a configuration setting with the given name.

func (*DeafAdder) GetStringArray

func (d *DeafAdder) GetStringArray(path string) (v []string, err error)

GetStringArray returns the []string value of a configuration setting with the given name.

func (*DeafAdder) GetStringSlice

func (d *DeafAdder) GetStringSlice(path string) (v []string, err error)

GetStringSlice returns the []string value of a configuration setting with the given name.

func (*DeafAdder) GetUint

func (d *DeafAdder) GetUint(path string) (v uint, err error)

GetUint returns the uint value of a configuration setting with the given name.

func (*DeafAdder) GetUint8

func (d *DeafAdder) GetUint8(path string) (v uint8, err error)

GetUint8 returns the uint8 value of a configuration setting with the given name.

func (*DeafAdder) GetUint16

func (d *DeafAdder) GetUint16(path string) (v uint16, err error)

GetUint16 returns the uint16 value of a configuration setting with the given name.

func (*DeafAdder) GetUint32

func (d *DeafAdder) GetUint32(path string) (v uint32, err error)

GetUint32 returns the uint32 value of a configuration setting with the given name.

func (*DeafAdder) GetUint64

func (d *DeafAdder) GetUint64(path string) (v uint64, err error)

GetUint64 returns the uint64 value of a configuration setting with the given name.

func (*DeafAdder) GetUintSlice

func (d *DeafAdder) GetUintSlice(path string) (v []uint, err error)

GetUintSlice returns the []uint value of a configuration setting with the given name.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL