-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (34 loc) · 806 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
// Copyright 2023 jhonwong. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/jhonwong/framework/framework/gin"
"github.com/jhonwong/framework/framework/middleware"
)
func main() {
core := gin.New()
core.Use(gin.Recovery())
core.Use(middleware.Cost())
registerRoute(core)
server := &http.Server{
Handler: core,
Addr: ":8888",
}
go func() {
server.ListenAndServe()
}()
//监听系统关闭信号
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
<-quit
if err := server.Shutdown(context.Background()); err != nil {
log.Fatal("Server Shutdown:", err)
}
}