-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (49 loc) · 1.17 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
package main
import (
"fmt"
"os"
"os/signal"
"sxp-server/app/router"
"sxp-server/common/grpc/client"
g "sxp-server/common/grpc/client"
ini "sxp-server/common/initial"
"sxp-server/common/kafka"
"sxp-server/common/logger"
"sxp-server/common/queue"
"sxp-server/config"
"time"
)
func main() {
l := logger.GetLogger()
go SetUp()
l.Info("########################### sxp项目启动中 #########################")
go queue.StartQueue() //开启延时队列
kafka.StartKafkaConsume() //开启kafka消费者
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit //优雅退出
kafka.StopKafkaConsume()
queue.GlobalQueue.StopConsume()
g.Stop()
ini.App.Cache.Close()
l.Infof("%s sxp服务停止 ... \r\n", time.Now().Format("2006-01-02 15:04:05"))
}
// SetUp
//
// @Description: 启动操作
func SetUp() {
app := ini.App
l := logger.GetLogger()
r := app.Engine
router.InitRouter(r)
err := client.Init() //初始化grpc客户端
if err != nil {
l.Panicf("初始化grpc-client失败:%s", err.Error())
}
port := fmt.Sprintf(":%s", config.Conf.Server.Port)
err = r.Run(port)
if err != nil {
l.Panicf("程序启动失败:%s", err.Error())
return
}
}