This commit is contained in:
16
main.go
16
main.go
@@ -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()
|
||||
|
Reference in New Issue
Block a user