-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (32 loc) · 691 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
package main
import (
"eoinisawesome.com/jumpcloud-takehome/app"
"errors"
"log"
"net/http"
"time"
)
func main() {
log.Println("starting")
shutdown := make(chan int)
httpServer := http.Server{
Addr: ":8080",
Handler: app.AppRouter(shutdown, 5*time.Second),
}
go func() {
log.Println("waiting for shutdown signal...")
<-shutdown
log.Println("got signal calling close!")
err := httpServer.Close()
if err != nil {
log.Fatalln("unable to close server", err)
return
}
}()
err := httpServer.ListenAndServe()
if errors.Is(err, http.ErrServerClosed) {
log.Println("server closed")
} else if err != nil {
log.Fatalln("error starting server", err)
}
}