-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (36 loc) · 864 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"
"log"
"os"
"os/signal"
"github.com/batt0s/goshort/controllers"
)
func main() {
appMode := os.Getenv("APP_MODE")
if appMode == "" {
appMode = "dev"
log.Println("[warning] No APP_MODE in env. Defaulting to dev.")
}
// Create and init app
app := controllers.App{}
app.Init(appMode)
// Gracefully shutdown
shutdown := make(chan struct{})
go func() {
sigint := make(chan os.Signal, 1)
// Interrupt signal sent from terminal
signal.Notify(sigint, os.Interrupt)
<-sigint
// when recieved a interrupt signal
log.Println("[info] Interrupt signal recieved. Gracefully stopping.")
err := app.Server.Shutdown(context.Background())
if err != nil {
log.Println("[error] HTTP Server Shutdown Error :", err.Error())
}
log.Println("[info] Stopped.")
close(shutdown)
}()
app.Run()
<-shutdown
}