config

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const STRUCT_TAG = "config"

Variables

This section is empty.

Functions

func AddBoolFlag

func AddBoolFlag(name string, value bool, usage string) *pflag.Flag

func AddBoolPFlag

func AddBoolPFlag(name string, value bool, usage string) *pflag.Flag

func AddConfigChangeEventListener

func AddConfigChangeEventListener(listener ConfigChangeEventHandler)

AddConfigChangeEventListener function is used to register any ConfigChangeEventHandler

func AddDurationFlag

func AddDurationFlag(name string, value time.Duration, usage string) *pflag.Flag

func AddFloat64Flag

func AddFloat64Flag(name string, value float64, usage string) *pflag.Flag

func AddInt16Flag

func AddInt16Flag(name string, value int16, usage string) *pflag.Flag

func AddInt32Flag

func AddInt32Flag(name string, value int32, usage string) *pflag.Flag

func AddInt64Flag

func AddInt64Flag(name string, value int64, usage string) *pflag.Flag

func AddInt8Flag

func AddInt8Flag(name string, value int8, usage string) *pflag.Flag

func AddIntFlag

func AddIntFlag(name string, value int, usage string) *pflag.Flag

func AddStringFlag

func AddStringFlag(name string, value string, usage string) *pflag.Flag

---------------------------------------------------------- Functions to add flags from a component

func AddUint16Flag

func AddUint16Flag(name string, value uint16, usage string) *pflag.Flag

func AddUint32Flag

func AddUint32Flag(name string, value uint32, usage string) *pflag.Flag

func AddUint64Flag

func AddUint64Flag(name string, value uint64, usage string) *pflag.Flag

func AddUint8Flag

func AddUint8Flag(name string, value uint8, usage string) *pflag.Flag

func AddUintFlag

func AddUintFlag(name string, value uint, usage string) *pflag.Flag

func AttachFlagCompletions

func AttachFlagCompletions(cmd *cobra.Command)

func AttachToFlagSet

func AttachToFlagSet(flagset *pflag.FlagSet)

AttachToFlagSet is used to attach the flags in config to the cmd flags

func BindEnv

func BindEnv(key string, envVarName string)

BindEnv binds the key parameter to a particular environment variable For a hierarchical structure pass the keys separated by a . For examples to access "name" field in the following structure:

auth:
	name: value

the key parameter should take on the value "auth.key"

func BindPFlag

func BindPFlag(key string, flag *pflag.Flag)

BindPFlag binds the key parameter to a particular flag For a hierarchical structure pass the keys separated by a . For examples to access "name" field in the following structure:

auth:
	name: value

the key parameter should take on the value "auth.key"

func DecryptConfigFile

func DecryptConfigFile(fileName string, passphrase string) error

func IsSet

func IsSet(key string) bool

func OnConfigChange

func OnConfigChange()

func ReadConfigFromReader

func ReadConfigFromReader(reader io.Reader) error

func ReadFromConfigBuffer

func ReadFromConfigBuffer(configData []byte) error

ReadFromConfigBuffer is used to the configFilePath and initialize viper object

func ReadFromConfigFile

func ReadFromConfigFile(configFilePath string) error

ReadFromConfigFile is used to the configFilePath and initialize viper object

func RegisterFlagCompletionFunc

func RegisterFlagCompletionFunc(flagName string, completionFunc func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective))

func ResetConfig

func ResetConfig()

func Set

func Set(key string, val string)

func SetBool

func SetBool(key string, val bool)

func SetConfigFile

func SetConfigFile(configFilePath string)

SetConfigFile : set config file name to be watched by viper

func SetSecureConfigOptions

func SetSecureConfigOptions(passphrase string)

func Unmarshal

func Unmarshal(obj interface{}) error

Unmarshal populates the passed object and all the exported fields. use lower case attribute names to ignore a particular field

func UnmarshalKey

func UnmarshalKey(key string, obj interface{}) error

UnmarshalKey is used to obtain a subtree starting from the key parameter For a hierarchical structure pass the keys separated by a . For examples to access "name" field in the following structure:

auth:
	name: value

the key parameter should take on the value "auth.key"

func WatchConfig

func WatchConfig()

Types

type ConfigChangeEventHandler

type ConfigChangeEventHandler interface {
	OnConfigChange()
}

ConfigChangeEventHandler is the interface that must implemented by any object that wants to be notified of changes in the config file

type ConfigChangeEventHandlerFunc

type ConfigChangeEventHandlerFunc func()

func (ConfigChangeEventHandlerFunc) OnConfigChange

func (handler ConfigChangeEventHandlerFunc) OnConfigChange()

type KeysTree

type KeysTree map[string]interface{}

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

func NewTree

func NewTree() *Tree

NewTree returns a new Tree object with the head initialized to a default root TreeNode

func (*Tree) GetSubTree

func (tree *Tree) GetSubTree(key string) *TreeNode

GetSubTree returns the sub Tree that is present from the last child of the key passed in. For eg. to retrieve the subtree starting from child2 the passed key can be root.child1.child2

func (*Tree) Insert

func (tree *Tree) Insert(key string, value interface{})

Insert function is used to insert a new object into the tree The key is specified as a dot separated hierarchical value For eg. root.child1.child2

func (*Tree) Merge

func (tree *Tree) Merge(obj interface{}, getValue func(val interface{}) (res interface{}, ok bool))

Merge performs the same function as MergeWithKey but at the root level

func (*Tree) MergeWithKey

func (tree *Tree) MergeWithKey(key string, obj interface{}, getValue func(val interface{}) (res interface{}, ok bool))

MergeWithKey is used to merge the contained tree with the object (obj) that is passed in as parameter. getValue parameter is a function that accepts the value stored in a TreeNode and performs any business logic and returns the value that has to be placed in the obj parameter it must also return true|false based on which the value will be set in the obj parameter.

func (*Tree) Print

func (tree *Tree) Print()

Print is a utility function that prints the Tree in a level order fashion

type TreeNode

type TreeNode struct {
	// contains filtered or unexported fields
}

func NewTreeNode

func NewTreeNode(name string) *TreeNode

NewTreeNode returns a TreeNode initialized with the passed in string as name

Jump to

Keyboard shortcuts

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