-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
83 lines (75 loc) · 1.84 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
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"strings"
"syscall"
log "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
yaag_gin "github.com/masato25/yaag/gin"
"github.com/masato25/yaag/yaag"
"github.com/open-falcon/falcon-plus/modules/api/app/controller"
"github.com/open-falcon/falcon-plus/modules/api/config"
"github.com/open-falcon/falcon-plus/modules/api/graph"
"github.com/spf13/viper"
)
func initGraph() {
graph.Start(viper.GetStringMapString("graphs.cluster"))
}
func main() {
cfgTmp := flag.String("c", "cfg.json", "configuration file")
version := flag.Bool("v", false, "show version")
help := flag.Bool("h", false, "help")
flag.Parse()
cfg := *cfgTmp
if *version {
fmt.Println(config.VERSION)
os.Exit(0)
}
if *help {
flag.Usage()
os.Exit(0)
}
viper.AddConfigPath(".")
viper.AddConfigPath("/")
viper.AddConfigPath("./config")
viper.AddConfigPath("./api/config")
cfg = strings.Replace(cfg, ".json", "", 1)
viper.SetConfigName(cfg)
err := viper.ReadInConfig()
if err != nil {
log.Fatal(err)
}
err = config.InitLog(viper.GetString("log_level"))
if err != nil {
log.Fatal(err)
}
err = config.InitDB(viper.GetBool("db.db_bug"))
if err != nil {
log.Fatalf("db conn failed with error %s", err.Error())
}
routes := gin.Default()
if viper.GetBool("gen_doc") {
yaag.Init(&yaag.Config{
On: true,
DocTitle: "Gin",
DocPath: viper.GetString("gen_doc_path"),
BaseUrls: map[string]string{"Production": "/api/v1", "Staging": "/api/v1"},
})
routes.Use(yaag_gin.Document())
}
initGraph()
//start gin server
log.Debugf("will start with port:%v", viper.GetString("web_port"))
go controller.StartGin(viper.GetString("web_port"), routes)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
fmt.Println()
os.Exit(0)
}()
select {}
}