-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (57 loc) · 1.51 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 (
"flag"
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/gin-gonic/gin"
"github.com/sugarshop/asgard-gateway/db"
"github.com/sugarshop/asgard-gateway/handler"
"github.com/sugarshop/asgard-gateway/mw"
"github.com/sugarshop/asgard-gateway/remote"
"github.com/sugarshop/asgard-gateway/service"
"github.com/sugarshop/env"
)
func main() {
// start config
var conf string
flag.StringVar(&conf, "conf", "conf/test.json", "specify the load config file")
flag.Parse()
// load env configuration
env.LoadGlobalEnv(conf)
engine := gin.New()
engine.Use(mw.ParseFormMiddleware)
engine.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
// init db
db.Init()
fmt.Println("[main]: db init success")
Init()
fmt.Println("[main]: service init success")
// register other api
handler.Register(engine)
fmt.Println("[main]: handler register success")
// Initializing the server in a goroutine so that
// it won't block the graceful shutdown handling below
// listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
go func() {
engine.Run()
}()
// Wait for interrupt signal to gracefully shutdown the server with
// a timeout of 5 seconds.
quit := make(chan os.Signal, 1)
// kill (no param) default send syscanll.SIGTERM
// kill -2 is syscall.SIGIN'T
// kill -9 is syscall.SIGKILL but can't be catch, so don't need add it
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
}
func Init() {
remote.Init()
service.Init()
}