mirror of
https://github.com/r-smith/deceptifeed.git
synced 2025-10-23 08:22:21 +00:00
Allow comments in exclude list
This change allows for comments in the exclude list using the `#` symbol. The `#` symbol on a line and everything after it is ignored when parsing the exclude list.
This commit is contained in:
@@ -118,7 +118,8 @@ loop:
|
|||||||
|
|
||||||
// parseExcludeList reads IP addresses and CIDR ranges from a file. Each line
|
// parseExcludeList reads IP addresses and CIDR ranges from a file. Each line
|
||||||
// should contain an IP address or CIDR. It returns a map of the unique IPs and
|
// should contain an IP address or CIDR. It returns a map of the unique IPs and
|
||||||
// a slice of the CIDR ranges found in the file.
|
// a slice of the CIDR ranges found in the file. The file may include comments
|
||||||
|
// using "#". The "#" symbol on a line and everything after is ignored.
|
||||||
func parseExcludeList(filepath string) (map[string]struct{}, []*net.IPNet, error) {
|
func parseExcludeList(filepath string) (map[string]struct{}, []*net.IPNet, error) {
|
||||||
if len(filepath) == 0 {
|
if len(filepath) == 0 {
|
||||||
return map[string]struct{}{}, []*net.IPNet{}, nil
|
return map[string]struct{}{}, []*net.IPNet{}, nil
|
||||||
@@ -137,6 +138,12 @@ func parseExcludeList(filepath string) (map[string]struct{}, []*net.IPNet, error
|
|||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := strings.TrimSpace(scanner.Text())
|
line := strings.TrimSpace(scanner.Text())
|
||||||
|
|
||||||
|
// Remove comments from text.
|
||||||
|
if i := strings.Index(line, "#"); i != -1 {
|
||||||
|
line = strings.TrimSpace(line[:i])
|
||||||
|
}
|
||||||
|
|
||||||
if len(line) > 0 {
|
if len(line) > 0 {
|
||||||
if _, ipnet, err := net.ParseCIDR(line); err == nil {
|
if _, ipnet, err := net.ParseCIDR(line); err == nil {
|
||||||
cidr = append(cidr, ipnet)
|
cidr = append(cidr, ipnet)
|
||||||
|
Reference in New Issue
Block a user