-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (44 loc) · 937 Bytes
/
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
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"pangolin/core"
"pangolin/web/controller"
"pangolin/web/router"
"syscall"
"time"
)
func main() {
e := new(core.Engine)
e.Init()
core.CoreEngine = e
//初始化服务
controller.NewServices()
// 注册路由
r := router.SetupRouter()
// 启动服务
srv := &http.Server{
Addr: "127.0.0.1:8080",
Handler: r,
}
go func() {
// 开启一个goroutine启动服务
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Println("listen:", err)
}
}()
// 优雅关机
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("Shutdown Server ...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
log.Println("Server Shutdown:", err)
}
log.Println("Server exiting")
}