forked from sryanyuan/gocodesite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (55 loc) · 1.2 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
package main
import (
"errors"
"flag"
"log"
"os"
"os/exec"
"path/filepath"
"github.com/cihub/seelog"
"github.com/sryanyuan/gocodesite/gocodecc"
)
func getModulePath() string {
file, _ := exec.LookPath(os.Args[0])
path, _ := filepath.Abs(file)
dir := filepath.Dir(path)
return dir
}
func initConf() error {
configpath := flag.String("config", "", "configpath <json config file path>")
flag.Parse()
if len(*configpath) == 0 {
flag.PrintDefaults()
return errors.New("Invalid config path")
}
return gocodecc.ReadJSONConfig(*configpath)
}
func main() {
var err error
// initialize log
logger, err := seelog.LoggerFromConfigAsFile(getModulePath() + "/static/conf/log.conf")
if nil == logger {
log.Println("Failed to initialize log module, error:", err)
os.Exit(1)
}
seelog.ReplaceLogger(logger)
// clean up
defer func() {
e := recover()
if nil != e {
seelog.Error("Main routine quit with error:", e)
} else {
seelog.Info("Main routine quit normally")
}
seelog.Flush()
}()
// load config
if err = initConf(); nil != err {
seelog.Error("Failed to init parameters:", err)
return
}
err = gocodecc.Start()
if nil != err {
seelog.Error("gocodecc error:", err)
}
}