-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (33 loc) · 753 Bytes
/
main.go
File metadata and controls
41 lines (33 loc) · 753 Bytes
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
package main
import (
"context"
"log/slog"
"os"
"os/signal"
"syscall"
"github.com/libops/cap/config"
"github.com/libops/cap/scraper"
)
func main() {
cfg, err := config.LoadFromEnv()
if err != nil {
slog.Error("Configuration error", "err", err)
os.Exit(1)
}
s, err := scraper.NewScraper(cfg, slog.Default(), os.Stderr)
if err != nil {
slog.Error("Failed to initialize scraper", "err", err)
os.Exit(1)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
go func() {
sig := <-sigChan
slog.Info("Received shutdown signal", "signal", sig)
cancel()
}()
s.Run(ctx)
slog.Info("Scraper stopped gracefully")
}