-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
40 lines (34 loc) · 985 Bytes
/
config.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"time"
)
type Config struct {
f interface{}
}
// As the logger can only be configured after we read the config
// I make use of the stdout for error logging
func (cfg Config) Init(fileName string) Config {
start := time.Now()
file, err := ioutil.ReadFile(fileName)
if err != nil {
fmt.Printf("%s \x1b[1;31m[%s] \x1b[0m : %s \n", "ERROR", err)
// os.Exit(0)
}
err = json.Unmarshal(file, &cfg.f)
if err != nil {
fmt.Printf("%s \x1b[1;31m[%s] \x1b[0m : %s \n", "ERROR", err)
// os.Exit(0)
}
fmt.Printf("%s \x1b[1;34m [%s] \x1b[0m : %s \n", start.Format("2006/01/02 03:04:05"), "INFO", "Reading config settings")
return cfg
}
func (cfg Config) Get(parent string, name string) string {
// manually decode hierarchy levels
conf := cfg.f.(map[string]interface{})["object"]
parentconf := conf.(map[string]interface{})[parent]
retval := parentconf.(map[string]interface{})[name].(string)
return retval
}