-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (45 loc) · 1.13 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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"catbox-scanner/internals/config"
"catbox-scanner/internals/database"
"catbox-scanner/internals/metrics"
"catbox-scanner/internals/scanner"
"github.com/panjf2000/ants/v2"
)
func main() {
cfg, err := config.LoadConfig("config.yaml")
if err != nil {
fmt.Printf("Error loading config: %v\n", err)
return
}
metricss := metrics.NewMetrics(60)
isRunning := true
db, err := database.NewDatabase(cfg.Database.ConnectionString)
if err != nil {
fmt.Printf("Failed to initialize database: %v\n", err)
return
}
defer db.Close()
pool, _ := ants.NewPool(
cfg.Scanner.NumWorkers,
ants.WithNonblocking(false),
ants.WithDisablePurge(true),
ants.WithPreAlloc(true),
)
scannerService := scanner.NewScanner(cfg, metricss, db, pool, &isRunning)
go metricss.StartPrintLoop(&isRunning)
go scannerService.StartScanning()
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
<-signalChan
fmt.Println("\nShutting down gracefully...")
isRunning = false
pool.ReleaseTimeout(time.Second)
db.Close()
fmt.Println("\nBye Bye~")
}