vconfig

package module
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2020 License: Apache-2.0 Imports: 9 Imported by: 3

README

Vconcfig

Handles the interactive case of synchronizing variables to viper config (ie. read-read the config, but don't reset variables that have been already set).

Documentation

Index

Constants

View Source
const (
	DebugKey   = "debug"   // bool
	VerboseKey = "verbose" // bool
)
 These are top level variables in, say, a YAML file.
 e.g. debug = true
 not:
 vconfig:
		 debug: true

Variables

View Source
var (
	ConfigFileName string
	ConfigFileRoot string
	HistoryFile    string
)
View Source
var (
	AppName = "application"
)

Functions

func Apply

func Apply()

Apply will set the viper variable with BindKey to the Value if there is a Value.

func ApplyFromFlags

func ApplyFromFlags(pflags *pflag.FlagSet)

ApplyFromFlags will look at each flag in the flag set and if the flag changed and there is a Binding it will set the viper value to the value of the flag (not the BindValue). This is where precedence is maintained essentially allowing for a switch having flags take short-term preccedence over sets.

func Debug

func Debug() bool

Debug returns whether debug mode is set.

func InitConfig

func InitConfig()

InitConfig reads in config file and ENV variables if set.

func ResetBindings

func ResetBindings()

ResetBindings will erase existing bindings. This is really used for Testing.

func Set

func Set(bk string, value interface{})

Set will set the viper variable and keep the value for later application during Apply.

func SetDebug

func SetDebug(b bool)

SetDebug allows you to turn on or off the debug mode.

func ToggleDebug

func ToggleDebug() bool

ToggleDebug toggles the flag and returns the new value.

func ToggleVerbose

func ToggleVerbose() bool

ToggleVerbose toggles the flag and returns the new value.

func UpdateChangedFlags

func UpdateChangedFlags()

UpdateChangedFlags will look at each binding and if the associated flag has changed, udpate the bind value. This is intended to be used to capture values to bind to viper right after a parse of flags has acurred. You might then immediately call Apply() to cause the viper variables to take this new value. This is different behavior than ApplyFromFlags.

func Verbose

func Verbose() bool

Verbose returs whether verbose mode is set.

Types

type BindFlag

type BindFlag struct {
	Flag    *pflag.Flag
	BindKey string
	// contains filtered or unexported fields
}

BindFlag - structure for dealing with values that propogate from the app command line flags.

func Bind

func Bind(bk string, f *pflag.Flag) (bf *BindFlag)

Bind a flag key to a flag variable. The reason we're doing this is because the viper pFlags integration doesn't doesn't comprehend multiple invocations. So, the first a key is bound to a flag, a new BindEntry is created. After that if a bind entry already exists, only the flag will be updated.

func GetBindFlags

func GetBindFlags() (bfs []*BindFlag)

GetBindFlags returns all the BindFlags registered.

Jump to

Keyboard shortcuts

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