mirror of
https://github.com/spf13/viper
synced 2025-05-06 20:27:17 +00:00
Add SetKeyDelimiter
Allow changing the Key Delimiter for accessing nested values. Fixes #170
This commit is contained in:
parent
d9cca5ef33
commit
056876e01f
2 changed files with 12 additions and 0 deletions
7
viper.go
7
viper.go
|
@ -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() }
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue