-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
79 lines (65 loc) · 1.29 KB
/
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
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
package main
import (
"encoding/json"
"log"
"os"
"os/signal"
"syscall"
)
const SYSTEM_PATH = "/etc/docker-entry.json"
var defaultConf = Configuration{
Docker_proto: "http",
Docker_serve_port: 2375,
Docker_api_version: "v1.24",
Listen: "127.0.0.1:8888",
Quick_Start: true,
}
func loadConf(path string) Configuration {
file, err := os.Open(path)
defer file.Close()
if err != nil {
if os.IsExist(err) {
log.Fatalf("%s not exist", path)
}
return defaultConf
}
from := &Configuration{
Quick_Start: true,
}
json.NewDecoder(file).Decode(&from)
to := defaultConf
mergeConf(&to, from)
log.Printf("Load Config\n")
return to
}
func mergeConf(to, from *Configuration) {
if from.Enable_sign {
to.Enable_sign = from.Enable_sign
}
if from.Debug {
to.Debug = from.Debug
}
if from.Quick_Start == false {
to.Quick_Start = from.Quick_Start
}
if len(from.App_keys) > 0 {
to.App_keys = from.App_keys
}
if from.Docker_proto != "" {
to.Docker_proto = from.Docker_proto
}
if from.Docker_api_version != "" {
to.Docker_api_version = from.Docker_api_version
}
if from.Listen != "" {
to.Listen = from.Listen
}
}
func reloadConf(path string) {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGUSR1)
for {
<-c
Config = loadConf(path)
}
}