Skip to content

Commit

Permalink
Little refactor
Browse files Browse the repository at this point in the history
* handle errors when writing the file
* Remove commented code
  • Loading branch information
MissingRoberto committed Jul 18, 2017
1 parent a0df6f5 commit a71bf28
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions goml/goml.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Set(yml *simpleyaml.Yaml, path string, val interface{}) error {
if index, err := strconv.Atoi(propName); err == nil {
tmp, props := get(yml, newPath)
if props == nil {
return errors.New("peroperty not found")
return errors.New("property not found")
}

prop, err := tmp.Array()
Expand Down Expand Up @@ -259,9 +259,7 @@ func WriteYaml(yml *simpleyaml.Yaml, file string) error {
return err
}

ioutil.WriteFile(file, gomlSave, 0644)

return nil
return ioutil.WriteFile(file, gomlSave, 0644)
}

func ReadYaml(yaml []byte) (*simpleyaml.Yaml, error) {
Expand All @@ -278,15 +276,7 @@ func ReadYamlFromFile(filename string) (*simpleyaml.Yaml, error) {
return nil, err
}

//val := yaml.MapSlice{}
//err = yaml.Unmarshal([]byte(file), &val)
//if err != nil {
//return nil, errors.New("unmarshal []byte to yaml failed: " + err.Error())
//}
//fmt.Printf("--- m:\n%v\n\n", val)

yml, _ := simpleyaml.NewYaml(file)
return yml, nil
return simpleyaml.NewYaml(file)
}

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

0 comments on commit a71bf28

Please sign in to comment.