mirror of
https://github.com/spf13/viper
synced 2024-06-16 16:59:08 +00:00
Merge 3dca0c3bbf
into ea35b92596
This commit is contained in:
commit
7d47b8f313
8
viper.go
8
viper.go
|
@ -1527,6 +1527,14 @@ func (v *Viper) SetEnvKeyReplacer(r *strings.Replacer) {
|
|||
v.envKeyReplacer = r
|
||||
}
|
||||
|
||||
// SetKeyDelimiter sets the delimiter used for determining key parts on the viper
|
||||
// object.
|
||||
func SetKeyDelimiter(d string) { v.SetKeyDelimiter(d) }
|
||||
|
||||
func (v *Viper) SetKeyDelimiter(d string) {
|
||||
v.keyDelim = d
|
||||
}
|
||||
|
||||
// RegisterAlias creates an alias that provides another accessor for the same key.
|
||||
// This enables one to change a name without breaking the application.
|
||||
func RegisterAlias(alias, key string) { v.RegisterAlias(alias, key) }
|
||||
|
|
|
@ -2573,6 +2573,54 @@ func TestKeyDelimiter(t *testing.T) {
|
|||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSetKeyDelimiter(t *testing.T) {
|
||||
v := New()
|
||||
v.SetKeyDelimiter("::")
|
||||
v.SetConfigType("yaml")
|
||||
r := strings.NewReader(string(yamlExampleWithDot))
|
||||
|
||||
err := v.unmarshalReader(r, v.config)
|
||||
require.NoError(t, err)
|
||||
|
||||
values := map[string]interface{}{
|
||||
"image": map[string]interface{}{
|
||||
"repository": "someImage",
|
||||
"tag": "1.0.0",
|
||||
},
|
||||
"ingress": map[string]interface{}{
|
||||
"annotations": map[string]interface{}{
|
||||
"traefik.frontend.rule.type": "PathPrefix",
|
||||
"traefik.ingress.kubernetes.io/ssl-redirect": "true",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
v.SetDefault("charts::values", values)
|
||||
|
||||
assert.Equal(t, "leather", v.GetString("clothing::jacket"))
|
||||
assert.Equal(t, "01/02/03", v.GetString("emails::steve@hacker.com::created"))
|
||||
|
||||
type config struct {
|
||||
Charts struct {
|
||||
Values map[string]interface{}
|
||||
}
|
||||
}
|
||||
|
||||
expected := config{
|
||||
Charts: struct {
|
||||
Values map[string]interface{}
|
||||
}{
|
||||
Values: values,
|
||||
},
|
||||
}
|
||||
|
||||
var actual config
|
||||
|
||||
assert.NoError(t, v.Unmarshal(&actual))
|
||||
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
var yamlDeepNestedSlices = []byte(`TV:
|
||||
- title: "The Expanse"
|
||||
title_i18n:
|
||||
|
|
Loading…
Reference in a new issue