-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.go
More file actions
71 lines (66 loc) · 1.77 KB
/
Copy pathmain.go
File metadata and controls
71 lines (66 loc) · 1.77 KB
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
package main
import (
"common/models"
"common/myconf"
_ "demo"
"fmt"
"github.com/gin-gonic/gin"
"github.com/lostvip-com/lv_framework/lv_global"
"github.com/lostvip-com/lv_framework/lv_log"
"github.com/lostvip-com/lv_framework/lv_log/lv_log_impl"
"github.com/lostvip-com/lv_framework/utils/lv_json"
"github.com/lostvip-com/lv_framework/web/server"
"os"
"os/signal"
"syscall"
_ "system"
)
var httpSvr *server.MyHttpServer
// @title LV 自动生成API文档
// @version 1.0
// @description 生成文档请在调试模式下进行<a href="/tool/swagger?a=r">重新生成文档</a>
// @host localhost
// @BasePath /
func main() {
fmt.Println("---------test--->" + lv_json.ToJsonStr(new(models.BaseModel)))
cfg := myconf.GetConfigInstance()
log := lv_log_impl.InitLog(cfg.GetAppName() + ".log")
lv_log.Log = log
if lv_global.IsDebug {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
}
//启动http 端口监听
go server.NewHttpServer().ListenAndServe()
//启动grpc 端口监听
//go rpcserver.NewRPCServer().ListenAndServe()
//监听信号
catchSignal()
}
// 捕捉信号
func catchSignal() {
lv_log.Info("⛲ ⛲ ⛲ ⛲ ⛲ ⛲ running! ⛲ ⛲ ⛲ ⛲ ⛲ ⛲ ")
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
for {
s := <-c
lv_log.Info("⛳ 收到信号:", s)
switch s {
case syscall.SIGHUP:
lv_log.Info("收到终端断开信号, 忽略")
case syscall.SIGINT, syscall.SIGTERM:
shutdown()
}
}
}
// 应用退出
func shutdown() {
defer func() {
lv_log.Info("⛔️ 已经退出应用!")
os.Exit(0)
}()
lv_log.Info("⌛ 即将停止服务!")
httpSvr.ShutDown()
lv_log.Info("❌ 已经停止服务!")
}