-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (42 loc) · 939 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
package main
import (
"context"
"net/http"
"os"
"os/signal"
"time"
"github.com/rwandaopensource/botx/database"
"github.com/rwandaopensource/botx/helper"
"github.com/rwandaopensource/botx/route"
"github.com/rwandaopensource/botx/util"
)
func main() {
defer database.Close()
if util.Command() {
return
}
ADDR := os.Getenv("PORT")
if ADDR == "" {
ADDR = ":8080"
}
s := &http.Server{
Addr: ADDR,
Handler: route.NewRouter(),
ReadTimeout: 20 * time.Second,
WriteTimeout: 20 * time.Second,
MaxHeaderBytes: 1 << 20,
}
helper.Print("starting server", ADDR)
go func() {
helper.FatalError(s.ListenAndServe(), "")
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
// Block until we receive our signal.
<-c
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
helper.Verbose("gracefully shutting down")
s.Shutdown(ctx)
return
}