Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Case-sensitive keys are one of the most request features of Viper. See #1014.
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 an (opaque) map with string keys that are case-sensitive. Ideally, if the map 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.
Viper's default behavior 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. This merge request implements case-sensitive keys in a manner that respects the existing behavior of the "global" Viper, and gives users an option to create a Viper that uses case-sensitive keys behavior.