forked from goraz/onion
/
loader.go
41 lines (33 loc) · 822 Bytes
/
loader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Package tomlloader is used to handle toml file in Onion file/folder layer.
// for using this package, just import it
//
// import (
// _ "github.com/fzerorubigd/onion/tomlloader"
// )
//
// There is no need to do anything else, if you load a file with toml
// extension, the toml loader is doing his job.
package tomlloader
import (
"io"
"io/ioutil"
"github.com/BurntSushi/toml"
"github.com/fzerorubigd/onion"
)
type tomlLoader struct {
}
func (tl tomlLoader) SupportedEXT() []string {
return []string{".toml"}
}
func (tl tomlLoader) Convert(r io.Reader) (map[string]interface{}, error) {
data, _ := ioutil.ReadAll(r)
ret := make(map[string]interface{})
err := toml.Unmarshal(data, &ret)
if err != nil {
return nil, err
}
return ret, nil
}
func init() {
onion.RegisterLoader(&tomlLoader{})
}