forked from BruceDone/clock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (48 loc) · 973 Bytes
/
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
package main
import (
"clock/config"
"clock/param"
"clock/server"
"clock/storage"
"flag"
"fmt"
"github.com/sirupsen/logrus"
"os"
)
var (
filePath string // 配置文件路径
help bool // 帮助
)
func usage() {
fmt.Fprintf(os.Stdout, `clock - simlpe scheduler
Usage: clock [-h help] [-c ./config.yaml]
Options:
`)
flag.PrintDefaults()
}
func main() {
flag.StringVar(&filePath, "c", "./config.yaml", "配置文件所在")
flag.BoolVar(&help, "h", false, "帮助")
flag.Usage = usage
flag.Parse()
if help {
flag.PrintDefaults()
return
}
// 设置配置文件和静态变量
config.SetConfig(filePath)
param.SetStatic()
storage.SetDb()
defer storage.Db.Close()
address := config.Config.GetString("server.host")
if address == "" {
logrus.Fatal("can not find any server host config")
}
engine, err := server.CreateEngine()
if err != nil {
logrus.Fatal(err)
}
if e := engine.Start(address); e != nil {
logrus.Fatal(e)
}
}