-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
53 lines (49 loc) · 1.04 KB
/
conf.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
package util
import (
"encoding/json"
"os"
"strings"
)
// settings
type Settings struct {
HttpPort int
MulticastEnable bool
Name string
NodeList []string
TcpPort int
LogPath string
ConfigFile string
DownloadInterval int
}
func NewSettings() *Settings {
return &Settings{
HttpPort: 8200,
MulticastEnable: false,
Name: "guess",
NodeList: []string{"127.0.0.1:8300"},
TcpPort: 8300,
LogPath: "../log",
DownloadInterval: 1,
}
}
// load json config
// change 127.0.0.1 to basic ip
func LoadSettingFromFile(fileName string, setting *Settings) {
file, err := os.Open(fileName)
if err != nil {
panic(err)
}
decoder := json.NewDecoder(file)
err = decoder.Decode(setting)
if err != nil {
panic(err)
}
for index, node := range setting.NodeList {
nodeInfo := strings.Split(node, ":")
if nodeInfo[0] != "127.0.0.1" {
continue
}
newNodeInfo := GetLocalIp() + ":" + nodeInfo[1]
setting.NodeList[index] = newNodeInfo
}
}