-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.go
85 lines (66 loc) · 1.71 KB
/
setup.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
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"encoding/json"
"io/ioutil"
"strconv"
"time"
)
var Config map[string]interface{}
var persistence bool
var port string
var gcInterval time.Duration
var diskWriteInterval time.Duration
// read the config file, if there's any
func readConfig() {
Config = make(map[string]interface{})
file, e := ioutil.ReadFile("/etc/mumbo-conf.json")
if e != nil {
extendConfig(Config)
} else {
json.Unmarshal(file, &Config)
// extend config with defaults
extendConfig(Config)
}
// initialize the system
initializer()
}
// will initialize the system with/ without persistence
func initializer() {
if persistence {
// initialize disk storage
initializeDiskStorage()
}
// initialize the basic structure, load the persistence values etc
initializeStore()
// intialize random garbage collection
go collectionGarbageCycle()
}
// will extend the config will defaults , if props not specified
func extendConfig(conf map[string]interface{}) {
_, ok := conf["persistence"]
if ok {
persistence = Config["persistence"].(bool)
} else {
persistence = false
}
_, ok = conf["port"]
if ok {
Fport := Config["port"].(float64)
Iport := int(Fport)
port = ":" + strconv.Itoa(int(Iport))
} else {
port = ":" + "2700"
}
_, ok = conf["gcInterval"]
if ok {
gcInterval = time.Duration(int(Config["gcInterval"].(float64)))
} else {
gcInterval = 100
}
_, ok = conf["diskWriteInterval"]
if ok {
diskWriteInterval = time.Duration(int(Config["gcInterval"].(float64)))
} else {
diskWriteInterval = 100
}
}