-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
45 lines (37 loc) · 996 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
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/henrywhitaker3/adguard-exporter/internal/adguard"
"github.com/henrywhitaker3/adguard-exporter/internal/config"
"github.com/henrywhitaker3/adguard-exporter/internal/http"
"github.com/henrywhitaker3/adguard-exporter/internal/metrics"
"github.com/henrywhitaker3/adguard-exporter/internal/worker"
)
func main() {
metrics.Init()
global, err := config.FromEnv()
if err != nil {
panic(err)
}
clients := []*adguard.Client{}
for _, conf := range global.Configs {
clients = append(clients, adguard.NewClient(conf))
}
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
http := http.NewHttp(global.Server.Debug)
go http.Serve()
go worker.Work(ctx, global.Server.Interval, clients)
http.Ready(true)
http.Healthy(true)
<-sigs
if err := http.Stop(ctx); err != nil {
panic(err)
}
}