Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoFlagDefined = vterrors.New(vtrpc.Code_INVALID_ARGUMENT, "flag not defined")
ErrNoFlagDefined is returned when a Value has a FlagName set, but the given FlagSet does not define a flag with that name.
Functions ¶
func BindFlags ¶
func BindFlags(fs *pflag.FlagSet, values ...Registerable)
BindFlags creates bindings between each value's registry and the given flag set. This function will panic if any of the values defines a flag that does not exist in the flag set.
Types ¶
type Base ¶
type Base[T any] struct { KeyName string DefaultVal T GetFunc func(v *viper.Viper) func(key string) T BoundGetFunc func(key string) T Aliases []string FlagName string EnvVars []string }
Base is the base functionality shared by Static and Dynamic values. It implements viperutil.Value.
func (*Base[T]) Flag ¶
Flag is part of the Registerable interface. If the given flag set has a flag with the name of this value's configured flag, that flag is returned, along with a nil error. If no flag exists on the flag set with that name, an error is returned.
If the value is not configured to correspond to a flag (FlagName == ""), then (nil, nil) is returned.
type Dynamic ¶
Dynamic is a dynamic value. Dynamic values register to the Dynamic registry, and respond to changes to watched config files. Their Get() methods will return whatever value is currently live in the config, in a threadsafe manner.
func NewDynamic ¶
NewDynamic returns a dynamic value derived from the given base value, after binding it to the dynamic registry and wrapping its GetFunc to be threadsafe with respect to config reloading.
type Registerable ¶
type Registerable interface { Key() string Registry() registry.Bindable Flag(fs *pflag.FlagSet) (*pflag.Flag, error) }
Registerable is the subset of the interface exposed by Values (which is declared in the public viperutil package).
We need a separate interface type because Go generics do not let you define a function that takes Value[T] for many, different T's, which we want to do for BindFlags.
type Static ¶
Static is a static value. Static values register to the Static registry, and do not respond to changes to config files. Their Get() method will return the same value for the lifetime of the process.