-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
42 lines (39 loc) · 873 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
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
)
func main() {
log.Println("HTTP Redirect " + AppVersion)
GetConfig().ReadConfig()
GetConfig().Print()
ListenAndServe()
}
func ListenAndServe() {
log.Println("Initializing REST services...")
httpServer := &http.Server{
Addr: GetConfig().ListenAddr,
WriteTimeout: time.Second * 15,
ReadTimeout: time.Second * 15,
IdleTimeout: time.Second * 60,
Handler: &Handler{},
}
go func() {
if err := httpServer.ListenAndServe(); err != nil {
log.Fatal(err)
os.Exit(-1)
}
}()
log.Println("HTTP Server listening on", GetConfig().ListenAddr)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
log.Println("Shutting down...")
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
httpServer.Shutdown(ctx)
}