-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
46 lines (38 loc) · 1014 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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/uma-arai/sbcntr-backend/infrastructure"
)
const (
envTLSCert = "TLS_CERT"
envTLSKey = "TLS_KEY"
)
func main() {
// Wait for interrupt signal to gracefully shutdown the server with a timeout of 10 seconds.
// Use a buffered channel to avoid missing signals as recommended for signal.Notify
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGTERM)
router := infrastructure.Router()
// Start server
go func() {
if os.Getenv(envTLSCert) == "" || os.Getenv(envTLSKey) == "" {
router.Logger.Fatal(router.Start(":80"))
} else {
router.Logger.Fatal(router.StartTLS(":443",
os.Getenv(envTLSCert), os.Getenv(envTLSKey)))
}
}()
<-quit
fmt.Println("Caught SIGTERM, shutting down")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := router.Shutdown(ctx); err != nil {
router.Logger.Fatal("Error:", err)
}
fmt.Println("Exited app")
}