-
Notifications
You must be signed in to change notification settings - Fork 0
/
providers.go
72 lines (57 loc) · 1.44 KB
/
providers.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package configo
import (
"encoding/json"
"github.com/flynn/json5"
"github.com/hjson/hjson-go"
"github.com/pelletier/go-toml/v2"
"gopkg.in/yaml.v3"
)
type ProviderFunc func(in []byte) (map[string]interface{}, error)
func (p ProviderFunc) Parse(in []byte) (map[string]interface{}, error) {
return p(in)
}
func parseYaml(in []byte) (map[string]interface{}, error) {
data := map[string]interface{}{}
err := yaml.Unmarshal(in, &data)
if err != nil {
return nil, err
}
return data, nil
}
func parseJson(in []byte) (map[string]interface{}, error) {
data := map[string]interface{}{}
err := json.Unmarshal(in, &data)
if err != nil {
return nil, err
}
return data, nil
}
func parseJson5(in []byte) (map[string]interface{}, error) {
data := map[string]interface{}{}
err := json5.Unmarshal(in, &data)
if err != nil {
return nil, err
}
return data, nil
}
func parseHjson(in []byte) (map[string]interface{}, error) {
data := map[string]interface{}{}
err := hjson.Unmarshal(in, &data)
if err != nil {
return nil, err
}
return data, nil
}
func parseToml(in []byte) (map[string]interface{}, error) {
data := map[string]interface{}{}
err := toml.Unmarshal(in, &data)
if err != nil {
return nil, err
}
return data, nil
}
var yamlProvider = ProviderFunc(parseYaml)
var jsonProvider = ProviderFunc(parseJson)
var json5Provider = ProviderFunc(parseJson5)
var hjsonProvider = ProviderFunc(parseHjson)
var tomlProvider = ProviderFunc(parseToml)