mirror of
https://github.com/therootcompany/golib.git
synced 2026-04-24 12:48:00 +00:00
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:
parent
7aa4493cb0
commit
d8b6638d97
@ -84,9 +84,6 @@ func main() {
|
|||||||
cfg.CacheDir = d
|
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, "")
|
repo := gitshallow.New(cfg.RepoURL, filepath.Join(cfg.CacheDir, "bitwire-it"), 1, "")
|
||||||
group := dataset.NewGroup(repo)
|
group := dataset.NewGroup(repo)
|
||||||
cfg.inbound = dataset.Add(group, func() (*ipcohort.Cohort, error) {
|
cfg.inbound = dataset.Add(group, func() (*ipcohort.Cohort, error) {
|
||||||
@ -101,12 +98,9 @@ func main() {
|
|||||||
repo.FilePath("tables/outbound/networks.txt"),
|
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)
|
log.Fatalf("blocklists: %v", err)
|
||||||
}
|
}
|
||||||
go group.Tick(ctx, refreshInterval, func(err error) {
|
|
||||||
log.Printf("refresh: %v", err)
|
|
||||||
})
|
|
||||||
|
|
||||||
maxmind := filepath.Join(cfg.CacheDir, "maxmind")
|
maxmind := filepath.Join(cfg.CacheDir, "maxmind")
|
||||||
geo, err := geoip.OpenDatabases(
|
geo, err := geoip.OpenDatabases(
|
||||||
@ -123,6 +117,12 @@ func main() {
|
|||||||
if cfg.Bind == "" {
|
if cfg.Bind == "" {
|
||||||
return
|
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 {
|
if err := cfg.serve(ctx); err != nil {
|
||||||
log.Fatalf("serve: %v", err)
|
log.Fatalf("serve: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user