Skip to content

Commit e1ea553

Browse files
authored
Merge pull request #1 from jszroberto/master
Add support for float keys
2 parents 2dbb4d4 + a71bf28 commit e1ea553

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

goml/goml.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func ExtractType(value *simpleyaml.Yaml) (interface{}, error) {
4040
if v, err := value.Int(); err == nil {
4141
return strconv.Itoa(v), nil
4242
}
43+
if v, err := value.Float(); err == nil {
44+
return fmt.Sprint(v), nil
45+
}
4346
if v, err := value.Array(); err == nil {
4447
strSl := []string{}
4548
for _, val := range v {
@@ -65,6 +68,8 @@ func extractArrayType(value interface{}) string {
6568
return strconv.FormatBool(value.(bool))
6669
case int:
6770
return strconv.Itoa(value.(int))
71+
case float64:
72+
return fmt.Sprint(value.(float64))
6873
}
6974
return ""
7075
}
@@ -78,7 +83,7 @@ func Set(yml *simpleyaml.Yaml, path string, val interface{}) error {
7883
if index, err := strconv.Atoi(propName); err == nil {
7984
tmp, props := get(yml, newPath)
8085
if props == nil {
81-
return errors.New("peroperty not found")
86+
return errors.New("property not found")
8287
}
8388

8489
prop, err := tmp.Array()
@@ -228,6 +233,10 @@ func SetValueForType(yaml *simpleyaml.Yaml, path string, value *simpleyaml.Yaml)
228233
err := Set(yaml, path, v)
229234
return err
230235
}
236+
if v, err := value.Float(); err == nil {
237+
err := Set(yaml, path, v)
238+
return err
239+
}
231240
if v, err := value.Array(); err == nil {
232241
err := Set(yaml, path, v)
233242
return err
@@ -250,9 +259,7 @@ func WriteYaml(yml *simpleyaml.Yaml, file string) error {
250259
return err
251260
}
252261

253-
ioutil.WriteFile(file, gomlSave, 0644)
254-
255-
return nil
262+
return ioutil.WriteFile(file, gomlSave, 0644)
256263
}
257264

258265
func ReadYaml(yaml []byte) (*simpleyaml.Yaml, error) {
@@ -269,15 +276,7 @@ func ReadYamlFromFile(filename string) (*simpleyaml.Yaml, error) {
269276
return nil, err
270277
}
271278

272-
//val := yaml.MapSlice{}
273-
//err = yaml.Unmarshal([]byte(file), &val)
274-
//if err != nil {
275-
//return nil, errors.New("unmarshal []byte to yaml failed: " + err.Error())
276-
//}
277-
//fmt.Printf("--- m:\n%v\n\n", val)
278-
279-
yml, _ := simpleyaml.NewYaml(file)
280-
return yml, nil
279+
return simpleyaml.NewYaml(file)
281280
}
282281

283282
func get(yml *simpleyaml.Yaml, path string) (*simpleyaml.Yaml, []string) {

0 commit comments

Comments
 (0)