@@ -40,6 +40,9 @@ func ExtractType(value *simpleyaml.Yaml) (interface{}, error) {
40
40
if v , err := value .Int (); err == nil {
41
41
return strconv .Itoa (v ), nil
42
42
}
43
+ if v , err := value .Float (); err == nil {
44
+ return fmt .Sprint (v ), nil
45
+ }
43
46
if v , err := value .Array (); err == nil {
44
47
strSl := []string {}
45
48
for _ , val := range v {
@@ -65,6 +68,8 @@ func extractArrayType(value interface{}) string {
65
68
return strconv .FormatBool (value .(bool ))
66
69
case int :
67
70
return strconv .Itoa (value .(int ))
71
+ case float64 :
72
+ return fmt .Sprint (value .(float64 ))
68
73
}
69
74
return ""
70
75
}
@@ -78,7 +83,7 @@ func Set(yml *simpleyaml.Yaml, path string, val interface{}) error {
78
83
if index , err := strconv .Atoi (propName ); err == nil {
79
84
tmp , props := get (yml , newPath )
80
85
if props == nil {
81
- return errors .New ("peroperty not found" )
86
+ return errors .New ("property not found" )
82
87
}
83
88
84
89
prop , err := tmp .Array ()
@@ -228,6 +233,10 @@ func SetValueForType(yaml *simpleyaml.Yaml, path string, value *simpleyaml.Yaml)
228
233
err := Set (yaml , path , v )
229
234
return err
230
235
}
236
+ if v , err := value .Float (); err == nil {
237
+ err := Set (yaml , path , v )
238
+ return err
239
+ }
231
240
if v , err := value .Array (); err == nil {
232
241
err := Set (yaml , path , v )
233
242
return err
@@ -250,9 +259,7 @@ func WriteYaml(yml *simpleyaml.Yaml, file string) error {
250
259
return err
251
260
}
252
261
253
- ioutil .WriteFile (file , gomlSave , 0644 )
254
-
255
- return nil
262
+ return ioutil .WriteFile (file , gomlSave , 0644 )
256
263
}
257
264
258
265
func ReadYaml (yaml []byte ) (* simpleyaml.Yaml , error ) {
@@ -269,15 +276,7 @@ func ReadYamlFromFile(filename string) (*simpleyaml.Yaml, error) {
269
276
return nil , err
270
277
}
271
278
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 )
281
280
}
282
281
283
282
func get (yml * simpleyaml.Yaml , path string ) (* simpleyaml.Yaml , []string ) {
0 commit comments