|
|
@ -4,6 +4,7 @@ import ( |
|
|
"bytes" |
|
|
"bytes" |
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"net/url" |
|
|
"net/url" |
|
|
|
|
|
"sync" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
"golang.org/x/net/html" |
|
|
"golang.org/x/net/html" |
|
|
@ -44,6 +45,29 @@ func (c fileChecker) Check(f string) ([]urlResult, error) { |
|
|
return rs, nil |
|
|
return rs, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c fileChecker) CheckMany(fs []string, rc chan fileResult) { |
|
|
|
|
|
wg := sync.WaitGroup{} |
|
|
|
|
|
|
|
|
|
|
|
for _, f := range fs { |
|
|
|
|
|
wg.Add(1) |
|
|
|
|
|
|
|
|
|
|
|
go func(f string) { |
|
|
|
|
|
rs, err := c.Check(f) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
rc <- fileResult{filename: f, err: err} |
|
|
|
|
|
} else { |
|
|
|
|
|
rc <- fileResult{filename: f, urlResults: rs} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wg.Done() |
|
|
|
|
|
}(f) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wg.Wait() |
|
|
|
|
|
close(rc) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func extractURLs(n *html.Node) []string { |
|
|
func extractURLs(n *html.Node) []string { |
|
|
us := make(map[string]bool) |
|
|
us := make(map[string]bool) |
|
|
ns := make([]*html.Node, 0, 1024) |
|
|
ns := make([]*html.Node, 0, 1024) |
|
|
|