-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
50 lines (43 loc) · 1004 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
package main
import (
"context"
"errors"
"flag"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/boardsite-io/server/internal/config"
"github.com/boardsite-io/server/internal/server"
"github.com/boardsite-io/server/pkg/log"
)
func main() {
ctx := context.Background()
cfgPath := flag.String("config", "./config.yaml", "path to the config file")
flag.Parse()
runServer(ctx, *cfgPath)
}
func runServer(ctx context.Context, cfgPath string) {
cfg, err := config.New(cfgPath)
if err != nil {
log.Global().Fatalf("parse config file: %v", err)
}
s := server.New(cfg)
run, shutdown := s.Serve(ctx)
defer shutdown()
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
go func() {
select {
case <-stop:
log.Global().Warn("Shutting down...")
if err := shutdown(); err != nil {
log.Global().Fatal(err)
}
os.Exit(0)
}
}()
if err := run(); !errors.Is(err, http.ErrServerClosed) {
log.Global().Fatal(err)
}
}