-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (40 loc) · 978 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
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"time"
)
func main() {
logger().Print("FloorFinder is up and running")
srv := &http.Server{
Handler: router(),
Addr: fmt.Sprintf(":%s", os.Getenv("HTTP_SERVER_PORT")),
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
idleConnectionsClosed := make(chan struct{})
go func() {
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt)
<-sigint
if err := srv.Shutdown(context.Background()); err != nil {
logger().Printf("HTTP server Shutdown: %v", err)
}
close(idleConnectionsClosed)
}()
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
logger().Fatalf("HTTP server ListenAndServe: %v", err)
}
<-idleConnectionsClosed
logger().Print("FloorFinder is down")
}
func logger() *log.Logger {
prefix := ""
loggerRef = log.New(os.Stdout, prefix, log.LstdFlags)
return loggerRef
}
var loggerRef *log.Logger