refactor(middleware): replace Cloudflare IP range fetching with bytes.Lines

This commit is contained in:
yusing
2025-08-30 11:26:10 +08:00
parent cc00859963
commit 2c6690b2d0

View File

@@ -1,6 +1,7 @@
package middleware package middleware
import ( import (
"bytes"
"context" "context"
"errors" "errors"
"fmt" "fmt"
@@ -115,11 +116,11 @@ func fetchUpdateCFIPRange(endpoint string, cfCIDRs *[]*nettypes.CIDR) error {
return err return err
} }
for _, line := range strutils.SplitLine(string(body)) { for line := range bytes.Lines(body) {
if line == "" { if len(line) == 0 {
continue continue
} }
_, cidr, err := net.ParseCIDR(line) _, cidr, err := net.ParseCIDR(string(line))
if err != nil { if err != nil {
return fmt.Errorf("cloudflare responeded an invalid CIDR: %s", line) return fmt.Errorf("cloudflare responeded an invalid CIDR: %s", line)
} }