diff --git a/yaml/yaml.go b/yaml/yaml.go index 482b8bc7238a13828033d1abbbdee64ddf172ace..171ae60c032666528fc5ba64f177cfa902e6ba07 100644 --- a/yaml/yaml.go +++ b/yaml/yaml.go @@ -31,6 +31,8 @@ import ( "strings" ) +const SEPARATOR = "/" + type Yaml struct { file string values *Tuple @@ -88,7 +90,7 @@ func (y *Yaml) Get(path string, defaultValue interface{}) interface{} { p = *y.values - chunks := strings.Split(path, ".") + chunks := strings.Split(path, SEPARATOR) length := len(chunks) @@ -123,7 +125,7 @@ func (y *Yaml) Get(path string, defaultValue interface{}) interface{} { return defaultValue } -// Sets a YAML setting, use dots (.) to nest values inside values. +// Sets a YAML setting, use diagonals (/) to nest values inside values. func (y *Yaml) Set(path string, value interface{}) { var p Tuple @@ -131,7 +133,7 @@ func (y *Yaml) Set(path string, value interface{}) { p = *y.values - chunks := strings.Split(path, ".") + chunks := strings.Split(path, SEPARATOR) length := len(chunks) diff --git a/yaml/yaml_test.go b/yaml/yaml_test.go index da62497a5882dd029586fa05a23beb897c1c5367..d20e6a5e2da287a7d3044385d4e97c85d3db6d59 100644 --- a/yaml/yaml_test.go +++ b/yaml/yaml_test.go @@ -24,7 +24,7 @@ func TestGet(t *testing.T) { } test3 := "Third" - val3 := settings.Get("test_map.element_3.test_sequence", nil).([]interface{}) + val3 := settings.Get("test_map/element_3/test_sequence", nil).([]interface{}) if val3[2] != test3 { t.Errorf("Got %t expecting %t.", val3[2], test3) @@ -70,10 +70,10 @@ func TestGet(t *testing.T) { func TestSet(t *testing.T) { settings := Open("examples/input/settings.yaml") - settings.Set("test_map.element_3.test_bool", true) + settings.Set("test_map/element_3/test_bool", true) test1 := true - val1 := settings.Get("test_map.element_3.test_bool", nil).(bool) + val1 := settings.Get("test_map/element_3/test_bool", nil).(bool) if val1 != test1 { t.Errorf("Got %t expecting %t.", val1, test1) @@ -85,6 +85,6 @@ func TestWrite(t *testing.T) { settings := New() defer settings.Write("examples/input/settings2.yaml") - settings.Set("test_map.element_3.test_bool", true) + settings.Set("test_map/element_3/test_bool", true) }