-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
55 lines (43 loc) · 1 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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/astaxie/beego"
"github.com/toolkits/logger"
"github.com/coraldane/ops-meta/db"
"github.com/coraldane/ops-meta/g"
"github.com/coraldane/ops-meta/http"
"github.com/coraldane/ops-meta/models"
"github.com/coraldane/ops-meta/store"
)
func main() {
cfg := flag.String("c", "cfg.json", "configuration file")
version := flag.Bool("v", false, "show version")
flag.Parse()
if *version {
fmt.Println(g.VERSION)
os.Exit(0)
}
if err := g.ParseConfig(*cfg); err != nil {
log.Fatalln(err)
}
logger.SetLevelWithDefault(g.Config().LogLevel, "info")
models.Init()
db.Init()
go store.RefreshDesiredAgent()
go store.CleanStaleHost()
addr := g.Config().Listen.Addr
if "" == addr {
addr = "127.0.0.1"
}
if 0 >= g.Config().Listen.Port {
return
}
beego.BConfig.CopyRequestBody = true
beego.BConfig.WebConfig.Session.SessionOn = true
beego.BConfig.Listen.HTTPAddr = addr
beego.BConfig.Listen.HTTPPort = g.Config().Listen.Port
http.Start()
}