2022-01-01 16:02:57 +00:00
|
|
|
package viper
|
|
|
|
|
|
|
|
var yamlExample = []byte(`Hacker: true
|
|
|
|
name: steve
|
|
|
|
hobbies:
|
|
|
|
- skateboarding
|
|
|
|
- snowboarding
|
|
|
|
- go
|
|
|
|
clothing:
|
Add CaseSensitiveKeys option
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.
2023-10-20 22:09:25 +00:00
|
|
|
Jacket: leather
|
2022-01-01 16:02:57 +00:00
|
|
|
trousers: denim
|
Add CaseSensitiveKeys option
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.
2023-10-20 22:09:25 +00:00
|
|
|
Pants:
|
2022-01-01 16:02:57 +00:00
|
|
|
size: large
|
|
|
|
age: 35
|
|
|
|
eyes : brown
|
|
|
|
beard: true
|
|
|
|
`)
|
|
|
|
|
|
|
|
var yamlWriteExpected = []byte(`age: 35
|
|
|
|
beard: true
|
|
|
|
clothing:
|
|
|
|
jacket: leather
|
|
|
|
pants:
|
|
|
|
size: large
|
|
|
|
trousers: denim
|
|
|
|
eyes: brown
|
|
|
|
hacker: true
|
|
|
|
hobbies:
|
|
|
|
- skateboarding
|
|
|
|
- snowboarding
|
|
|
|
- go
|
|
|
|
name: steve
|
|
|
|
`)
|
|
|
|
|
|
|
|
var yamlExampleWithDot = []byte(`Hacker: true
|
|
|
|
name: steve
|
|
|
|
hobbies:
|
|
|
|
- skateboarding
|
|
|
|
- snowboarding
|
|
|
|
- go
|
|
|
|
clothing:
|
|
|
|
jacket: leather
|
|
|
|
trousers: denim
|
|
|
|
pants:
|
|
|
|
size: large
|
|
|
|
age: 35
|
|
|
|
eyes : brown
|
|
|
|
beard: true
|
|
|
|
emails:
|
|
|
|
steve@hacker.com:
|
|
|
|
created: 01/02/03
|
|
|
|
active: true
|
|
|
|
`)
|