-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
40 lines (35 loc) · 988 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"
"io/ioutil"
"log"
"time"
)
// Config holds add configuration for app
type Config struct {
PersistanceModel string `json:"persistance_model"`
MongoURL string `json:"mongo_url"`
MySQLURL string `json:"mysql_url"`
ProxyPool map[string]string `json:"proxy_pool"`
Duration time.Duration `json:"duration"`
ChanSize int `json:"chan_size"`
TaskRoutines int `json:"task_routines"`
}
var config Config
func globalConfig() Config {
return config
}
func loadConfigOrDie() {
data, err := ioutil.ReadFile("config.json")
if err != nil {
log.Fatalf("load config.json failed: %v, use default config", err)
}
err = json.Unmarshal(data, &config)
if err != nil {
log.Fatalf("unmarshal config.json failed: %v, use default config\n", err)
}
// register proxy
for name, addr := range config.ProxyPool {
registerProxy(name, addr)
}
}