/
main.go
45 lines (36 loc) · 867 Bytes
/
main.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
package hades
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
// exists returns whether the given file or directory exists
func exists(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
return false
}
// getPath returns whichever path exists
func getPath(file string, paths []string) string {
for _, path := range paths {
filePath := path + "/" + file
if exists(filePath) {
return filePath
}
}
panic("Invalid Paths")
}
// GetConfig returns a map of all config in a toml file
func GetConfig(file string, paths []string) Config {
filePath := getPath(file, paths)
content, _ := ioutil.ReadFile(filePath)
config := map[interface{}]interface{}{}
err := yaml.Unmarshal(content, &config)
if err != nil {
panic(fmt.Sprintf("Cant Load Yaml Config Because Of Error %+v", err))
}
return Config{data: config}
}