-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (45 loc) · 835 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"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/tmeire/go-web-scaffold/pkg/environment"
"github.com/tmeire/go-web-scaffold/pkg/o11y"
"github.com/tmeire/go-web-scaffold/pkg/web"
)
func main() {
ctx := context.Background()
conf := environment.Parse()
o11y.StartPProfServer()
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
mux := http.NewServeMux()
web.Register(mux)
server := &http.Server{
Addr: ":8080",
Handler: o11y.Register(ctx, conf, mux),
}
done := make(chan struct{})
go func() {
err := server.ListenAndServe()
if err != nil {
panic(err)
}
close(done)
}()
select {
case <-sigc:
err := server.Close()
if err != nil {
panic(err)
}
case <-done:
return
}
}