Skip to content

Commit

Permalink
code-smells reduced, x/net/html version bump (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
s0rg authored Dec 19, 2021
1 parent 079d02b commit cc3eba7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/s0rg/crawley

go 1.17

require golang.org/x/net v0.0.0-20211209124913-491a49abca63
require golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
golang.org/x/net v0.0.0-20211209124913-491a49abca63 h1:iocB37TsdFuN6IBRZ+ry36wrkoV51/tl5vOWqkcPGvY=
golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
1 change: 1 addition & 0 deletions pkg/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (h *HTTP) request(req *http.Request) (body io.ReadCloser, hdrs http.Header,
return resp.Body, resp.Header, err
}

// Discard read all contents from ReaderCloser, closing it afterwards.
func Discard(rc io.ReadCloser) {
_, _ = io.Copy(io.Discard, rc)
_ = rc.Close()
Expand Down
18 changes: 7 additions & 11 deletions pkg/crawler/crawl.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ const (
type taskFlag byte

const (
// TaskDefault marks result for printing only.
TaskDefault taskFlag = iota
// TaskCrawl marks result as can-be-crawled.
TaskCrawl
// TaskDone marks result as final - crawling end here.
TaskDone
)

Expand Down Expand Up @@ -156,20 +159,13 @@ func (c *Crawler) crawl(base *url.URL, t *crawlResult) (yes bool) {
return
}

if !canCrawl(base, u, c.cfg.Depth) {
return
}

if c.robots.Forbidden(u.Path) {
return
}

if c.cfg.Dirs == DirsOnly && isResorce(u.Path) {
switch {
case !canCrawl(base, u, c.cfg.Depth), c.robots.Forbidden(u.Path), c.cfg.Dirs == DirsOnly && isResorce(u.Path):
return
default:
go func(r *url.URL) { c.crawlCh <- r }(u)
}

go func(r *url.URL) { c.crawlCh <- r }(u)

return true
}

Expand Down

0 comments on commit cc3eba7

Please sign in to comment.