-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
89 lines (84 loc) · 1.87 KB
/
main.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
86
87
88
89
package main
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego/logs"
"os"
"time"
)
func getLevel(level string) int {
switch level {
case "debug":
return logs.LevelDebug
case "trace":
return logs.LevelTrace
case "warn":
return logs.LevelWarn
case "info":
return logs.LevelInfo
case "error":
return logs.LevelError
default:
return logs.LevelDebug
}
}
func initLog() (err error) {
//初始化日志库
config := make(map[string]interface{})
config["filename"] = appConfig.LogPath
config["level"] = getLevel(appConfig.LogLevel)
configStr, err := json.Marshal(config)
if err != nil {
fmt.Println(" json.Marshal failed,err:", err)
return
}
logs.SetLogger(logs.AdapterFile, string(configStr))
return
}
func main() {
//export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
//export PKG_CONFIG_PATH=/usr/lib/pkgconfig/
os.Setenv("PKG_CONFIG_PATH", "/usr/local/lib/pkgconfig/")
err := initConfig()
if err != nil {
panic(fmt.Sprintf("init config failed,err:%v\n", err))
}
err = initLog()
if err != nil {
return
}
logs.Debug("init success")
ipArrays, err = getLocalIP()
logs.Info(ipArrays)
if err != nil {
logs.Error("get local ip failed, err:%v", err)
return
}
//TODO 内网 外网区别内网kafka 外网http
logs.Debug("get local ip succ, ips:%v", ipArrays)
// init kafka sender
switch appConfig.startType {
case "kafka":
err = InitKafkaKDC()
logs.Info("Init Kafka Connection")
if err != nil {
logs.Error("init kafka failed, err:%v", err)
return
}
case "http":
// init http sender
logs.Info("Init Http Connection")
err = InitHttpPusher()
if err != nil {
logs.Error("init http failed, err:%v", err)
return
}
}
err = initEtcd(appConfig.etcdAddr, appConfig.etcdWatchKeyFmt,
time.Duration(appConfig.etcdTimeout)*time.Millisecond)
if err != nil {
logs.Error("init etcd failed, err:%v", err)
return
}
RunServer()
}