-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (38 loc) · 1.05 KB
/
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
51
package main
import (
"os"
"os/signal"
"syscall"
"time"
"github.com/bygui86/go-postgres/logging"
"github.com/bygui86/go-postgres/rest"
)
func main() {
logging.Log.Info("Start go-traces")
restServer := startRestServer()
logging.Log.Info("go-traces up&running")
startSysCallChannel()
shutdownAndWait(restServer, 3)
}
func startRestServer() *rest.Server {
logging.Log.Debug("Start REST server")
server, err := rest.NewServer()
if err != nil {
logging.SugaredLog.Errorf("REST server creation failed: %s", err.Error())
os.Exit(501)
}
logging.Log.Debug("REST server successfully created")
server.Start()
logging.Log.Debug("REST server successfully started")
return server
}
func startSysCallChannel() {
syscallCh := make(chan os.Signal)
signal.Notify(syscallCh, syscall.SIGTERM, syscall.SIGINT, os.Interrupt)
<-syscallCh
}
func shutdownAndWait(restServer *rest.Server, timeout int) {
logging.SugaredLog.Warnf("Termination signal received! Timeout %d", timeout)
restServer.Shutdown(timeout)
time.Sleep(time.Duration(timeout+1) * time.Second)
}