Skip to content

Commit c66508b

Browse files
committed
yml support
1 parent f110a73 commit c66508b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

yaml.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package gonfig
2+
3+
import (
4+
"gopkg.in/yaml.v2"
5+
"io"
6+
"io/ioutil"
7+
)
8+
9+
// FromYml reads the contents from the supplied reader.
10+
// The content is parsed as json into a map[string]interface{}.
11+
// It returns a JsonGonfig struct pointer and any error encountered
12+
func FromYml(reader io.Reader) (Gonfig, error) {
13+
14+
inputBytes, err := ioutil.ReadAll(reader)
15+
if err != nil {
16+
return nil, err
17+
}
18+
var obj map[string]interface{}
19+
if err := yaml.Unmarshal(inputBytes, &obj); err != nil {
20+
return nil, err
21+
}
22+
return &JsonGonfig{obj}, nil
23+
}

0 commit comments

Comments
 (0)