Documentation ¶
Index ¶
- Variables
- func AllKeys() []string
- func AllSettings() map[string]interface{}
- func AutomaticEnv()
- func Get(key string) interface{}
- func GetBool(key string) bool
- func GetDuration(key string) time.Duration
- func GetFloat32(key string) float32
- func GetFloat64(key string) float64
- func GetInt(key string) int
- func GetInt32(key string) int32
- func GetInt64(key string) int64
- func GetString(key string) string
- func GetStringSlice(key string) []string
- func GetUint(key string) uint
- func GetUint32(key string) uint32
- func GetUint64(key string) uint64
- func IsSet(key string) bool
- func MergeConfig(in io.Reader) error
- func MergeInConfig() error
- func ReadConfig(in io.Reader) error
- func ReadInConfig() error
- func Reset()
- func Set(key string, value interface{})
- func SetConfigFile(in string)
- func SetConfigPaths(noExtName string, paths ...string)
- func SetConfigType(in string) error
- func SetEnvKeyReplacer(r *strings.Replacer)
- func SetEnvPrefix(in string)
- func WatchConfig(onChange func(in fsnotify.Event))
- type BoolFlag
- type Command
- func (c *Command) AddCobraCommand(cmds ...*cobra.Command)
- func (c *Command) AddCommand(cmds ...*Command)
- func (c *Command) AddFlag(fs ...Flag) error
- func (c *Command) CobraCommands() []*cobra.Command
- func (c *Command) Commands() []*Command
- func (c *Command) RemoveCobraCommand(cmds ...*cobra.Command)
- func (c *Command) RemoveCommand(cmds ...*Command)
- type DurationFlag
- type Flag
- type Float32Flag
- type Float64Flag
- type Int32Flag
- type Int64Flag
- type IntFlag
- type StringFlag
- type StringSliceFlag
- type Uint32Flag
- type Uint64Flag
- type UintFlag
Constants ¶
This section is empty.
Variables ¶
var ( // UnderlineReplacer replace dash of underline UnderlineReplacer = strings.NewReplacer("-", "_") )
Functions ¶
func AllKeys ¶
func AllKeys() []string
AllKeys returns all keys holding a value, regardless of where they are set. Nested keys are returned with a v.keyDelim (= ".") separator
func AllSettings ¶
func AllSettings() map[string]interface{}
AllSettings merges all settings and returns them as a map[string]interface{}.
func AutomaticEnv ¶
func AutomaticEnv()
AutomaticEnv has Mamba check ENV variables for all. keys set in config, default & flags
func Get ¶
func Get(key string) interface{}
Get can retrieve any value given the key to use. Get is case-insensitive for a key. Get has the behavior of returning the value associated with the first place from where it is set. Viper will check in the following order: override, flag, env, config file, key/value store, default
Get returns an interface. For a specific value use one of the Get____ methods.
func GetDuration ¶
GetDuration returns the value associated with the key as a time.Duration.
func GetFloat32 ¶
GetFloat32 returns the value associated with the key as a float32.
func GetFloat64 ¶
GetFloat64 returns the value associated with the key as a float64.
func GetStringSlice ¶
GetStringSlice returns the value associated with the key as a []string.
func IsSet ¶
IsSet checks to see if the key has been set in any of the data locations. IsSet is case-insensitive for a key
func MergeConfig ¶
MergeConfig merges a new configuration with an existing config. You should SetConfigType before read config
func MergeInConfig ¶
func MergeInConfig() error
MergeInConfig merges a new configuration with an existing config.
func ReadConfig ¶
ReadConfig will read a configuration file, setting existing keys to nil if the key does not exist in the file. You should SetConfigType before read config
func ReadInConfig ¶
func ReadInConfig() error
ReadInConfig will discover and load the configuration file from disk and key/value stores, searching in one of the defined paths.
func Reset ¶
func Reset()
Reset intends for testing, will reset all to default settings. In the public interface for the viper package so applications can use it in their testing as well.
func Set ¶
func Set(key string, value interface{})
Set sets the value for the key in the override regiser. Set is case-insensitive for a key. Will be used instead of values obtained via flags, config file, ENV, default, or key/value store.
func SetConfigFile ¶
func SetConfigFile(in string)
SetConfigFile explicitly defines the path, name and extension of the config file. Viper will use this and not check any of the config paths.
func SetConfigPaths ¶
SetConfigPaths adds paths for Viper to search for the config file in. The given file name should not contain a extension, e.g. 'json'.
func SetConfigType ¶
SetConfigType sets the type of the configuration, e.g. "json".
func SetEnvKeyReplacer ¶
SetEnvKeyReplacer sets the strings.Replacer on the viper object Useful for mapping an environmental variable to a key that does not match it.
func SetEnvPrefix ¶
func SetEnvPrefix(in string)
SetEnvPrefix defines a prefix that ENVIRONMENT variables will use. E.g. if your prefix is "spf", the env registry will look for env variables that start with "SPF_". Only work for automatic env
func WatchConfig ¶
WatchConfig watches the configuration file change
Types ¶
type BoolFlag ¶
type BoolFlag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue bool // points to a variable in which to store the value of the flag Destination *bool }
BoolFlag is a flag of type bool
func (BoolFlag) IsPersistent ¶
IsPersistent specify whether the flag is persistent
type Command ¶
Command contains a cobra.Command
func (*Command) AddCobraCommand ¶
AddCobraCommand adds one or more cobra commands to this parent command.
func (*Command) AddCommand ¶
AddCommand adds one or more commands to this parent command.
func (*Command) CobraCommands ¶
CobraCommands returns a sorted slice of child cobra commands.
func (*Command) RemoveCobraCommand ¶
RemoveCobraCommand removes one or more cobra commands from a parent command.
func (*Command) RemoveCommand ¶
RemoveCommand removes one or more commands from a parent command.
type DurationFlag ¶
type DurationFlag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue time.Duration // points to a variable in which to store the value of the flag Destination *time.Duration }
DurationFlag is a flag of type time.Duration
func (DurationFlag) ApplyTo ¶
func (f DurationFlag) ApplyTo(fs *pflag.FlagSet) error
ApplyTo adds the flag to given FlagSet
func (DurationFlag) GetName ¶
func (f DurationFlag) GetName() string
GetName returns the flag's name
func (DurationFlag) IsPersistent ¶
func (f DurationFlag) IsPersistent() bool
IsPersistent specify whether the flag is persistent
type Flag ¶
type Flag interface { // IsPersistent specify whether the flag is persistent IsPersistent() bool // GetName returns the flag's name GetName() string // ApplyTo adds the flag to a given FlagSet ApplyTo(*pflag.FlagSet) error }
Flag describes a flag interface
type Float32Flag ¶
type Float32Flag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue float32 // points to a variable in which to store the value of the flag Destination *float32 }
Float32Flag is a flag of type float32
func (Float32Flag) ApplyTo ¶
func (f Float32Flag) ApplyTo(fs *pflag.FlagSet) error
ApplyTo adds the flag to given FlagSet
func (Float32Flag) IsPersistent ¶
func (f Float32Flag) IsPersistent() bool
IsPersistent specify whether the flag is persistent
type Float64Flag ¶
type Float64Flag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue float64 // points to a variable in which to store the value of the flag Destination *float64 }
Float64Flag is a flag of type float64
func (Float64Flag) ApplyTo ¶
func (f Float64Flag) ApplyTo(fs *pflag.FlagSet) error
ApplyTo adds the flag to given FlagSet
func (Float64Flag) IsPersistent ¶
func (f Float64Flag) IsPersistent() bool
IsPersistent specify whether the flag is persistent
type Int32Flag ¶
type Int32Flag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue int32 // points to a variable in which to store the value of the flag Destination *int32 }
Int32Flag is a flag of type int32
func (Int32Flag) IsPersistent ¶
IsPersistent specify whether the flag is persistent
type Int64Flag ¶
type Int64Flag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue int64 // points to a variable in which to store the value of the flag Destination *int64 }
Int64Flag is a flag of type int64
func (Int64Flag) IsPersistent ¶
IsPersistent specify whether the flag is persistent
type IntFlag ¶
type IntFlag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue int // points to a variable in which to store the value of the flag Destination *int }
IntFlag is a flag of type int
func (IntFlag) IsPersistent ¶
IsPersistent specify whether the flag is persistent
type StringFlag ¶
type StringFlag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue string // points to a variable in which to store the value of the flag Destination *string }
StringFlag is a flag of type string
func (StringFlag) ApplyTo ¶
func (f StringFlag) ApplyTo(fs *pflag.FlagSet) error
ApplyTo adds the flag to given FlagSet
func (StringFlag) IsPersistent ¶
func (f StringFlag) IsPersistent() bool
IsPersistent specify whether the flag is persistent
type StringSliceFlag ¶
type StringSliceFlag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue []string // points to a variable in which to store the value of the flag Destination *[]string }
StringSliceFlag is a flag of type []string
func (StringSliceFlag) ApplyTo ¶
func (f StringSliceFlag) ApplyTo(fs *pflag.FlagSet) error
ApplyTo adds the flag to given FlagSet
func (StringSliceFlag) GetName ¶
func (f StringSliceFlag) GetName() string
GetName returns the flag's name
func (StringSliceFlag) IsPersistent ¶
func (f StringSliceFlag) IsPersistent() bool
IsPersistent specify whether the flag is persistent
type Uint32Flag ¶
type Uint32Flag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue uint32 // points to a variable in which to store the value of the flag Destination *uint32 }
Uint32Flag is a flag of type uint32
func (Uint32Flag) ApplyTo ¶
func (f Uint32Flag) ApplyTo(fs *pflag.FlagSet) error
ApplyTo adds the flag to given FlagSet
func (Uint32Flag) IsPersistent ¶
func (f Uint32Flag) IsPersistent() bool
IsPersistent specify whether the flag is persistent
type Uint64Flag ¶
type Uint64Flag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue uint64 // points to a variable in which to store the value of the flag Destination *uint64 }
Uint64Flag is a flag of type uint64
func (Uint64Flag) ApplyTo ¶
func (f Uint64Flag) ApplyTo(fs *pflag.FlagSet) error
ApplyTo adds the flag to given FlagSet
func (Uint64Flag) IsPersistent ¶
func (f Uint64Flag) IsPersistent() bool
IsPersistent specify whether the flag is persistent
type UintFlag ¶
type UintFlag struct { // Name as it appears on command line Name string // one-letter abbreviated flag Shorthand string // help message Usage string // specify whether the flag is persistent Persistent bool // used by cobra.Command bash autocomple code Annotations map[string][]string // If this flag is deprecated, this string is the new or now thing to use Deprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use ShorthandDeprecated string // used by cobra.Command to allow flags to be hidden from help/usage text Hidden bool // bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically // if EnvKey is set, it will override the automatic generated env key EnvKey string // the default value DefValue uint // points to a variable in which to store the value of the flag Destination *uint }
UintFlag is a flag of type uint
func (UintFlag) IsPersistent ¶
IsPersistent specify whether the flag is persistent