Add SetKeyDelimiter

Allow changing the Key Delimiter for accessing nested values.

Fixes #170
This commit is contained in:
Robert Günzler 2017-10-17 14:54:28 +02:00
parent d9cca5ef33
commit 056876e01f
2 changed files with 12 additions and 0 deletions

View file

@ -1560,6 +1560,13 @@ func (v *Viper) findConfigFile() (string, error) {
return "", ConfigFileNotFoundError{v.configName, fmt.Sprintf("%s", v.configPaths)}
}
func SetKeyDelimiter(in string) { v.SetKeyDelimiter(in) }
func (v *Viper) SetKeyDelimiter(in string) {
if in != "" {
v.keyDelim = in
}
}
// Debug prints all configuration registries for debugging
// purposes.
func Debug() { v.Debug() }

View file

@ -1181,6 +1181,11 @@ func doTestCaseInsensitive(t *testing.T, typ, config string) {
assert.Equal(t, 4, cast.ToInt(Get("ef.lm.no")))
assert.Equal(t, 5, cast.ToInt(Get("ef.lm.p.q")))
SetKeyDelimiter("::")
assert.Equal(t, 2, cast.ToInt(Get("ef::gh")))
assert.Equal(t, 3, cast.ToInt(Get("ef::ijk")))
assert.Equal(t, 4, cast.ToInt(Get("ef::lm::no")))
assert.Equal(t, 5, cast.ToInt(Get("ef::lm::p::q")))
}
func BenchmarkGetBool(b *testing.B) {