forked from fwtpe/owl-backend
/
main.go
89 lines (71 loc) · 1.78 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
86
87
88
89
package main
import (
"fmt"
"os"
"os/signal"
"github.com/spf13/viper"
oHttp "github.com/fwtpe/owl-backend/common/http"
"github.com/fwtpe/owl-backend/common/http/client"
"github.com/fwtpe/owl-backend/common/logruslog"
"github.com/fwtpe/owl-backend/common/vipercfg"
"github.com/fwtpe/owl-backend/modules/query/conf"
"github.com/fwtpe/owl-backend/modules/query/database"
"github.com/fwtpe/owl-backend/modules/query/g"
ginHttp "github.com/fwtpe/owl-backend/modules/query/gin_http"
"github.com/fwtpe/owl-backend/modules/query/graph"
"github.com/fwtpe/owl-backend/modules/query/grpc"
"github.com/fwtpe/owl-backend/modules/query/http"
"github.com/fwtpe/owl-backend/modules/query/proc"
)
func main() {
vipercfg.Parse()
vipercfg.Bind()
if vipercfg.Config().GetBool("version") {
fmt.Println(g.VERSION)
os.Exit(0)
}
// config
vipercfg.Load()
g.ParseConfig(vipercfg.Config().GetString("config"))
database.InitMySqlApi(loadMySqlApiConfig(vipercfg.Config()))
logruslog.Init()
gconf := g.Config()
// proc
proc.Start()
// graph
go graph.Start()
if gconf.Grpc.Enabled {
// grpc
go grpc.Start()
}
if gconf.GinHttp.Enabled {
//lambdaSetup
database.Init()
conf.ReadConf()
go ginHttp.StartWeb()
}
if gconf.Http.Enabled {
// http
go http.Start()
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
select {
case sig := <-c:
if sig.String() == "^C" {
os.Exit(3)
}
}
}
func loadMySqlApiConfig(viper *viper.Viper) *oHttp.RestfulClientConfig {
httpConfig := client.NewDefaultConfig()
httpConfig.Url = viper.GetString("mysql_api.host")
resource := viper.GetString("mysql_api.resource")
if resource != "" {
httpConfig.Url += "/" + resource
}
return &oHttp.RestfulClientConfig{
HttpClientConfig: httpConfig,
FromModule: "query",
}
}