Skip to content

Commit

Permalink
Merge branch 'master' of github.com:golobby/config
Browse files Browse the repository at this point in the history
  • Loading branch information
miladrahimi committed Jan 2, 2021
2 parents 5a598a7 + 294a64c commit c661119
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 5 additions & 3 deletions feeder/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package feeder

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
)

// Json is a feeder that feeds using a single json file.
Expand All @@ -12,14 +13,15 @@ type Json struct {

// Feed returns all the content.
func (j Json) Feed() (map[string]interface{}, error) {
content, err := ioutil.ReadFile(j.Path)
fl, err := os.Open(filepath.Clean(j.Path))
if err != nil {
return nil, err
}
defer fl.Close()

items := map[string]interface{}{}

if err := json.Unmarshal(content, &items); err != nil {
if err := json.NewDecoder(fl).Decode(&items); err != nil {
return nil, err
}

Expand Down
15 changes: 9 additions & 6 deletions feeder/yaml.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package feeder

import (
"os"
"path/filepath"

"gopkg.in/yaml.v2"
"io/ioutil"
)

type Yaml struct {
Path string
}

func (y *Yaml) Feed() (map[string]interface{}, error) {
bs, err := ioutil.ReadFile(y.Path)
fl, err := os.Open(filepath.Clean(y.Path))
if err != nil {
return nil, err
return nil, err
}
defer fl.Close()

items := make(map[string]interface{})

err = yaml.Unmarshal(bs, items)
if err != nil {
return nil, err
if err := yaml.NewDecoder(fl).Decode(&items); err != nil {
return nil, err
}
return items, nil
}

0 comments on commit c661119

Please sign in to comment.