feat(botfilter): add parseCIDRs
This commit is contained in:
1 parent
d8fba78dc9
commit
c8cb278162
1 file changed
+15
@@ -151,3 +151,18 @@ func applyDefaults(cfg, defaults *Config) {
|
||||
// an explicit YAML zero remains a useful way to disable one signal.
|
||||
}
|
||||
|
||||
func parseCIDRs(values []string, field string) ([]netip.Prefix, error) {
|
||||
result := make([]netip.Prefix, 0, len(values))
|
||||
for _, value := range values {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
prefix, err := netip.ParsePrefix(value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("botfilter: invalid %s entry %q: %w", field, value, err)
|
||||
}
|
||||
result = append(result, prefix.Masked())
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
Reference in new issue
Block a user