initial commit
This commit is contained in:
40
cmd/bind/parsing-simple.go
Normal file
40
cmd/bind/parsing-simple.go
Normal file
@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
)
|
||||
|
||||
func parseSimple(data []byte) []string {
|
||||
var domains []string
|
||||
|
||||
// convert data to reader for line-by-line reading
|
||||
r := bytes.NewReader(data)
|
||||
|
||||
// process combined files line-by-line
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
||||
// skip lines where the first non-whitespace character is '#' or '//'
|
||||
if regexp.MustCompile(`^(\s+)?(#|\/\/)`).MatchString(line) {
|
||||
continue
|
||||
}
|
||||
|
||||
// split line by whitespace
|
||||
lineItems := strings.Fields(line)
|
||||
|
||||
if len(lineItems) >= 1 {
|
||||
// the second item is the domain, check if its valid and add it
|
||||
if govalidator.IsDNSName(lineItems[0]) {
|
||||
domains = append(domains, lineItems[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return domains
|
||||
}
|
Reference in New Issue
Block a user