This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
/
main.go
85 lines (71 loc) · 1.44 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
package main
import (
"flag"
"fmt"
"os"
"runtime/pprof"
"github.com/golang/glog"
)
const (
VERSION = "2.0.0"
)
var (
configFile string
version bool
testMode bool
gitCommit string
profileFile string
)
func init() {
flag.StringVar(&configFile, "c", "config.json", "the config file")
flag.BoolVar(&version, "V", false, "show version")
flag.BoolVar(&testMode, "t", false, "test config")
flag.StringVar(&profileFile, "p", "", "log profile file")
}
func getVersion() string {
return fmt.Sprintf("%s-%s", VERSION, gitCommit)
}
func showVersion() {
fmt.Println(getVersion())
}
func main() {
// set default stderrthreshold to FATAL
flag.Set("stderrthreshold", "FATAL")
flag.Parse()
defer glog.Flush()
if profileFile != "" {
f, err := os.Create(profileFile)
if err != nil {
glog.Fatalf("Cannot start profiler: %v", err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
if version {
showVersion()
return
}
server := GetServer()
if testMode {
if err := server.Validate(configFile); err != nil {
fmt.Println("Invalid config, err: %v", err)
os.Exit(-1)
return
} else {
fmt.Println("Config is valid")
return
}
}
// server Init
if err := server.Init(configFile); err != nil {
fmt.Println("Invalid config, err: %v", err)
os.Exit(-1)
return
}
// server Run
if err := server.Run(); err != nil {
fmt.Println("Pusher exit unexpectedly, err: %v", err)
os.Exit(-1)
return
}
}