-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·47 lines (39 loc) · 908 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
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
. "zjutjh/Join-Us/config"
_ "zjutjh/Join-Us/db"
. "zjutjh/Join-Us/router"
JHLog "zjutjh/Join-Us/utility/log"
)
func main() {
var server *http.Server
var port string = ":" + Config.Server.Port
log.SetOutput(JHLog.LogMultiWriter)
log.Println("Running Server at", port)
server = &http.Server{
Addr: port,
Handler: Router,
}
go func() {
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("Listen: %s\n", err)
}
}()
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
<-quit
log.Println("Shutdown Server ...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
log.Fatal("Server Shutdown:", err)
}
log.Println("Server Exiting")
}