-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (45 loc) · 1005 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
51
52
53
54
55
56
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/krasio/gomate-web/handlers"
"github.com/krasio/gomate-web/version"
"github.com/urfave/negroni"
)
func main() {
log.Printf(
"[GOMATE] commit: %s, build time: %s, release: %s.",
version.Commit, version.BuildTime, version.Release,
)
port, ok := os.LookupEnv("GOMATE_PORT")
if !ok {
port = "8080"
}
router := handlers.Router()
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
n := negroni.Classic()
n.UseHandler(router)
srv := &http.Server{
Addr: ":" + port,
Handler: n,
}
go func() {
srv.ListenAndServe()
}()
log.Print("[GOMATE] Listening on :", port)
killSignal := <-interrupt
switch killSignal {
case os.Interrupt:
log.Print("[GOMATE] Got SIGINT.")
case syscall.SIGTERM:
log.Print("[GOMATE] Got SIGTERM.")
}
log.Print("[GOMATE] Shutting down...")
srv.Shutdown(context.Background())
log.Print("[GOMATE] Done.")
}