vor Instanzumbau
All checks were successful
release-tag / release-image (push) Successful in 1m33s

This commit is contained in:
2025-06-09 23:17:39 +02:00
parent eee9783562
commit 817d997263
2 changed files with 27 additions and 1 deletions

16
main.go
View File

@@ -180,6 +180,18 @@ func syncOnce(ctx context.Context, cfg Config, rdb *redis.Client, ranger *Ranger
return nil
}
func loadWhites(ctx context.Context, rdb *redis.Client, ranger *Ranger) error {
iter := rdb.Scan(ctx, 0, "wl:*", 0).Iterator()
for iter.Next(ctx) {
key := iter.Val() // "wl:1.2.3.4"
ipStr := strings.TrimPrefix(key, "wl:")
if ip, err := netip.ParseAddr(ipStr); err == nil {
ranger.addWhite(ip)
}
}
return iter.Err()
}
func processURL(ctx context.Context, url string, cb func(netip.Prefix)) error {
fmt.Println("Process URL:", url)
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
@@ -309,6 +321,10 @@ func main() {
log.Println("initial sync:", err)
}
if err := loadWhites(ctx, rdb, ranger); err != nil {
log.Println("loadWhites:", err)
}
go func() {
ticker := time.NewTicker(2 * time.Hour)
defer ticker.Stop()