-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
50 lines (43 loc) · 1022 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
package main
import (
"context"
"cumtBook/pkg/logging"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"time"
"cumtBook/pkg/setting"
"cumtBook/routers"
)
func main() {
router := routers.InitRouter()
s := &http.Server{
Addr: fmt.Sprintf(":%d", setting.HTTPPort),
Handler: router,
ReadTimeout: setting.ReadTimeout,
WriteTimeout: setting.WriteTimeout,
MaxHeaderBytes: 1 << 20,
}
log.Println("Listen to: ", setting.HTTPPort)
go func() {
if err := s.ListenAndServe(); err != nil {
log.Printf("Listen: %s\n", err)
logging.Info("Listen : ", err)
}
}()
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
log.Println("Shutdown Server ...")
logging.Info("Shutdown Server ...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := s.Shutdown(ctx); err != nil {
log.Fatal("Server Shutdown", err)
logging.Fatal("Server Shutdown", err)
}
log.Println("Server EXiting")
logging.Info("Server Exiting")
}