-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
73 lines (59 loc) · 1.41 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"context"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
config "github.com/Glimesh/waveguide/config"
inputs "github.com/Glimesh/waveguide/internal/inputs"
outputs "github.com/Glimesh/waveguide/internal/outputs"
control "github.com/Glimesh/waveguide/pkg/control"
"github.com/sirupsen/logrus"
)
func main() {
log := logrus.New()
hostname, err := os.Hostname()
if err != nil {
// How tf
log.Fatal(err)
}
log.Debugf("Server Hostname: %s", hostname)
cfg, err := config.Load()
if err != nil {
log.Fatalf("failed to read config: %v", err)
}
// Temporary for debugging
go func() {
log.Println(http.ListenAndServe(":6060", nil))
}()
level, err := logrus.ParseLevel(cfg.Control.LogLevel)
if err != nil {
log.Fatalf("failed to parse log level: %v", err)
}
log.SetLevel(level)
ctx, stop := signal.NotifyContext(
context.Background(),
os.Interrupt, syscall.SIGTERM, syscall.SIGINT,
)
ctrl, err := control.New(ctx, cfg, hostname, log)
if err != nil {
log.Fatalf("failed to create control: %v", err)
}
in, err := inputs.New(cfg, ctrl, log)
if err != nil {
log.Fatalf("failed to create inputs: %v", err)
}
in.Start(ctx)
out, err := outputs.New(cfg, ctrl, log)
if err != nil {
log.Fatalf("failed to create outputs: %v", err)
}
out.Start(ctx)
go ctrl.StartHTTPServer()
<-ctx.Done()
stop()
log.Info("Exiting Waveguide and cleaning up")
ctrl.Shutdown()
}