-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
49 lines (39 loc) · 1020 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
package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"time"
"github.com/haibeichina/gin_video_server/web/pkg/logging"
"github.com/haibeichina/gin_video_server/web/pkg/setting"
"github.com/haibeichina/gin_video_server/web/routers"
)
func main() {
setting.SetUp()
logging.SetUp()
router := routers.InitRouter()
s := &http.Server{
Addr: fmt.Sprintf(":%d", setting.ServerSetting.HTTPPort),
Handler: router,
ReadTimeout: setting.ServerSetting.ReadTimeout,
WriteTimeout: setting.ServerSetting.WriteTimeout,
MaxHeaderBytes: 1 << 20,
}
go func() {
if err := s.ListenAndServe(); err != nil {
logging.Infof("Listen: %s\n", err)
}
}()
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
logging.Info("Shutdown Server ...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := s.Shutdown(ctx); err != nil {
logging.Fatal("Server Shutdown:", err)
}
logging.Info("Server exiting")
}