When reading configuration from sources with case-sensitive keys,
such as YAML, TOML, and JSON, a user may wish to preserve the case
of keys that appear in maps. For example, consider when the value
of a setting is a map with string keys that are case-sensitive.
Ideally, if the value is not going to be indexed by a Viper lookup
key, then the map value should be treated as an opaque value by
Viper, and its keys should not be modified. See #1014
Viper's default behaviour is that keys are case-sensitive, and this
behavior is implemented by converting all keys to lower-case. For
users that wish to preserve the case of keys, this commit introduces
an Option `CaseSensitiveKeys()` that can be used to configure Viper
to use case-sensitive keys. When CaseSensitiveKeys is enabled, all
keys retain the original case, and lookups become case-sensitive
(except for lookups of values bound to environment variables).
The behavior of Viper could become hard to understand if a user
could change the CaseSensitiveKeys setting after values have been
stored. For this reason, the setting may only be set when creating
a Viper instance, and it cannot be set on the "global" Viper.
* Add DocBlock to WatchConfig
Added a small description of the WatchConfig().
So that you can understand in the ide why you could use it.
* Update viper.go
* update viper.go
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Co-authored-by: Márk Sági-Kazár <sagikazarmark@users.noreply.github.com>
Co-authored-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
One might want to write the debug information somewhere other than
Stdout. This patch adss a DebugTo function and method, that accepts
an io.Writer. It changes the original Debug implementation to call
this new function with a default of os.Stdout, which maintains
backward compatibility.
Signed-off-by: Brad P. Crochet <brad@redhat.com>
We have encountered numerous places where it is convenient to have viper return a `uint16` value, especially in combination with the new `netip` package that represents a port correctly as `uint16` rather than just an `int`. cobra already supports this, but we need a conversion from the existing `GetUint` method in viper.
The logger interface uses k,v pairs, but it was being called with a
format string, here.
Changed to use k,v pairs.
I didn't find any other instances of this problem.
Some codecs might have options that rely on Viper in the future
(eg. key delimiter) which requires initializing codecs
for each Viper instance.
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This interface is specific to decoding data into Viper's internal,
so it's okay to make it Viper specific.
BREAKING CHANGE: the decoder interface now accepts a map instead of an
interface
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
When merging a key where the target value is nil, the type of the target
and source do not match. What currently happens is an error is logged
and the key is skipped.
I have changed it so that it does the same thing as when the target key
is missing: copy the source value to the target.
Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
* Added support for accessing slices
* Processed PR feedback
- renamed searchMapWithPathPrefixes to searchIndexableWithPathPrefixes
- moved source type specific search logic to speparate functions
- Inverted if statments to avoid the arrow pattern
* Quickly return from searchSliceWithPathPrefixes and searchMapWithPathPrefixes functions without intermediate variables