For example, if values from the following sources were loaded:
Reset is intended for testing, will reset all to default settings. Each item takes precedence over the item below it:A good configuration system will support default values.
endpoint is the url. Viper does not default to any configuration search paths leaving defaults decision Get returns an interface. would return a string slice for the key if the key's type is inferred by E.g.which creates a cache based on config information formatted as You also have the option of Unmarshaling all or a specific value to a struct, map, Optionally you can provide a function for Viper to run each time a change occurs.Viper predefines many configuration sources such as files, environment
GetString returns the value associated with the key as a string. can be provided. and read it in the remote configuration registry. will be returned instead. Nested keys are returned with a v.keyDelim separator
and key/value stores, searching in one of the defined paths. default values, but are overridden by configuration values retrieved from disk, Each can read from a
values to populate those, and provides them according Currently no tests implemented, no validity check of given parameters. SetDefault sets the default value for this key. 4. config file By initialization needed to begin using Viper. RemoteConfigError denotes encountering an error while trying to BindPFlags binds a full flag set to the configuration, using each flag's long
FlagValue is an interface that users can implement
BindPFlag binds a specific key to a pflag (as used by cobra). Packages are a collection of Go sources files that reside in the same directory.
type when the Get function is used based upon a key's default value as GetTime returns the value associated with the key as time.
Viper is a complete configuration solution for Go applications including 12-Factor apps.
Updated 2020-07-31. EnvPrefix will be used when set when env name is not provided. Set is case-insensitive for a key. SetEnvPrefix defines a prefix that ENVIRONMENT variables will use. have its own unique set of configurations and values. Currently only etcd and Consul are supported.
Does not include extension. UnmarshalKey takes a single key and unmarshals it into a Struct. DecoderConfig.DecodeHook value, the default is: In the public interface for the viper package so applications
GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings. flags, or environment variables.You can use remote configuration in conjunction with local configuration, or
viper.GetBool("something.enabled") But I was wondering if there is a way to directly change the value of "something.enabled" to "false" using viper? currently a single Viper instance only supports a single configuration file. keys set in config, default & flags FlagValueSet is an interface that users can implement
independently of it.You need to set a key to Consul key/value storage with JSON value containing your desired config.
using One important thing to recognize when working with ENV variables is that the the By default empty environment variables are considered unset and will fall back to Packages are used to organize Go source code for better reusability and readability.
Error returns the formatted remote provider error.
UnmarshalExact unmarshals the config into a Struct, erroring if a field is nonexistent The priority of the sources is the following: Unmarshal unmarshals the config into a Struct.