-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
executable file
·79 lines (69 loc) · 1.69 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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"golang.org/x/sync/errgroup"
"os"
"os/signal"
"sync/atomic"
"syscall"
"time"
_ "yj-app/app/controller/router"
"yj-app/app/service/middleware/sessions"
"yj-app/app/service/middleware/sessions/memstore"
"yj-app/app/yjgframe/cfg"
_ "yj-app/app/yjgframe/cron"
"yj-app/app/yjgframe/server"
)
var (
g errgroup.Group
)
// @title 云捷GO 自动生成API文档
// @version 1.0
// @description 生成文档请在调试模式下进行<a href="/tool/swagger?a=r">重新生成文档</a>
// @host localhost
// @BasePath /api
func main() {
gin.SetMode("debug")
config := cfg.Instance()
if config == nil {
fmt.Printf("参数错误")
return
}
//后台服务状态
adminStatus := config.Status.Admin
//api服务状态
apiStatus := config.Status.Api
if adminStatus {
store := memstore.NewStore([]byte("secret"))
admin := server.New("admin", config.Admin.Address, gin.Logger(), sessions.Sessions("mysession", store))
admin.Template("template").Static(config.Admin.ServerRoot)
admin.Start(g)
}
if apiStatus {
api := server.New("api", config.Api.Address, gin.Recovery(), gin.Logger())
api.Start(g)
}
if err := g.Wait(); err != nil {
fmt.Println(err.Error())
}
var state int32 = 1
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
EXIT:
for {
sig := <-sc
fmt.Println("获取到信号[%s]", sig.String())
switch sig {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
atomic.StoreInt32(&state, 0)
break EXIT
case syscall.SIGHUP:
default:
break EXIT
}
}
fmt.Println("服务退出")
time.Sleep(time.Second)
os.Exit(int(atomic.LoadInt32(&state)))
}