refactor(check-ip): defer signal ctx + Tick until server starts

Signal handling and periodic refresh are only meaningful when the HTTP
server runs. Load blocklists with context.Background(); start Tick and
the signal-aware ctx inside the serve branch.
This commit is contained in:
AJ ONeal 2026-04-20 16:04:23 -06:00
parent 7aa4493cb0
commit d8b6638d97
No known key found for this signature in database

View File

@ -84,9 +84,6 @@ func main() {
cfg.CacheDir = d
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
repo := gitshallow.New(cfg.RepoURL, filepath.Join(cfg.CacheDir, "bitwire-it"), 1, "")
group := dataset.NewGroup(repo)
cfg.inbound = dataset.Add(group, func() (*ipcohort.Cohort, error) {
@ -101,12 +98,9 @@ func main() {
repo.FilePath("tables/outbound/networks.txt"),
)
})
if err := group.Load(ctx); err != nil {
if err := group.Load(context.Background()); err != nil {
log.Fatalf("blocklists: %v", err)
}
go group.Tick(ctx, refreshInterval, func(err error) {
log.Printf("refresh: %v", err)
})
maxmind := filepath.Join(cfg.CacheDir, "maxmind")
geo, err := geoip.OpenDatabases(
@ -123,6 +117,12 @@ func main() {
if cfg.Bind == "" {
return
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
go group.Tick(ctx, refreshInterval, func(err error) {
log.Printf("refresh: %v", err)
})
if err := cfg.serve(ctx); err != nil {
log.Fatalf("serve: %v", err)
}