Refactor IP parsing to use appendIfNotExcluded for exclusion validation and error handling
This commit is contained in:
+13
-3
@@ -146,7 +146,11 @@ func (p *textParser) Parse(body io.Reader, validator IPValidator, limit uint) (I
|
||||
continue
|
||||
}
|
||||
|
||||
ips = append(ips, ip)
|
||||
var err error
|
||||
ips, err = appendIfNotExcluded(ip, ips, validator)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if limit > 0 && uint(len(ips)) >= limit {
|
||||
break
|
||||
}
|
||||
@@ -186,9 +190,15 @@ func (p *textParser) ParseIPsByVersion(body io.Reader, validator IPValidator, li
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user