Refactor IP parsing to use appendIfNotExcluded for exclusion validation and error handling

This commit is contained in:
2026-08-12 16:29:09 +05:00
parent c22ef390ee
commit 407c9d961f
4 changed files with 53 additions and 9 deletions
+12 -3
View File
@@ -58,7 +58,10 @@ func (p *rssParser) Parse(body io.Reader, validator IPValidator, limit uint) (IP
continue
}
ips = append(ips, ip)
ips, err = appendIfNotExcluded(ip, ips, validator)
if err != nil {
return nil, err
}
if limit > 0 && uint(len(ips)) >= limit {
break
}
@@ -102,9 +105,15 @@ func (p *rssParser) ParseIPsByVersion(body io.Reader, validator IPValidator, lim
}
if ipVersion == IPVersion4 {
ipV4 = append(ipV4, ip)
ipV4, err = appendIfNotExcluded(ip, ipV4, validator)
if err != nil {
return nil, nil, err
}
} else if ipVersion == IPVersion6 {
ipV6 = append(ipV6, ip)
ipV6, err = appendIfNotExcluded(ip, ipV6, validator)
if err != nil {
return nil, nil, err
}
} else {
continue
}