-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·49 lines (41 loc) · 1.19 KB
/
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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/monzo/slog"
"github.com/monzo/typhon"
"github.com/chongyangshi/wylis/config"
"github.com/chongyangshi/wylis/incoming"
"github.com/chongyangshi/wylis/metrics"
"github.com/chongyangshi/wylis/outgoing"
)
func main() {
initContext := context.Background()
// Initialise server for incoming requests
svc := incoming.Service()
srv, err := typhon.Listen(svc, fmt.Sprintf("%s:%s", config.ConfigListenAddr, config.ConfigIncomingListenPort))
if err != nil {
panic(err)
}
slog.Info(initContext, "Wylis incoming listening on %v", srv.Listener().Addr())
// Initialise metcirs server
metrics.Init()
slog.Info(initContext, "Wylis metrics listening on %s", fmt.Sprintf("%s:%s", config.ConfigListenAddr, config.ConfigMetricsListenPort))
// Initialise client for outgoing requests
err = outgoing.Init(initContext)
if err != nil {
panic(err)
}
// Log termination gracefully
done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
<-done
slog.Info(initContext, "Wylis shutting down")
c, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
srv.Stop(c)
}