Skip to content

Commit a836c1c

Browse files
committed
Cleanup collector
1 parent fe76bbb commit a836c1c

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"fmt"
1212
"log/slog"
1313
"net/url"
14-
"slices"
14+
"os"
1515

1616
"github.com/google/uuid"
1717
)

internal/collector/collector.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,16 @@ func (c *Collector) IsVisitAllowed(in string) (bool, error) {
273273
return false, ErrCheckInternal
274274
}
275275

276+
// Treats www.domain.tld and domain.tld as equivalent.
276277
checkDomain := func(u *url.URL) bool {
277278
// Ensure there is at least one domain in the allowlist. Do not treat an
278279
// empty allowlist as a wildcard.
279-
if c.AllowDomains == nil || len(c.AllowDomains) == 0 {
280+
if len(c.AllowDomains) == 0 {
280281
slog.Error("No domains have been added to the allowlist.")
281282
return false
282283
}
283284

284-
naked := strings.TrimPrefix(p.Hostname(), "www.")
285+
naked := strings.TrimPrefix(u.Hostname(), "www.")
285286
www := fmt.Sprintf("www.%s", naked)
286287

287288
for _, allowed := range c.AllowDomains {

internal/collector/errors.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ import (
1111
)
1212

1313
var (
14-
ErrCheckInternal = errors.New("Internal check error")
14+
ErrCheckInternal = errors.New("internal check error")
1515

1616
// ErrForbiddenDomain is the error thrown if visiting
1717
// a domain which is not allowed in AllowedDomains
18-
ErrForbiddenDomain = errors.New("Forbidden domain")
19-
ErrForbiddenPath = errors.New("Forbidden path")
18+
ErrForbiddenDomain = errors.New("forbidden domain")
19+
ErrForbiddenPath = errors.New("forbidden path")
2020

2121
// ErrMissingURL is the error type for missing URL errors
22-
ErrMissingURL = errors.New("Missing URL")
22+
ErrMissingURL = errors.New("missing URL")
2323
// ErrMaxDepth is the error type for exceeding max depth
24-
ErrMaxDepth = errors.New("Max depth limit reached")
24+
ErrMaxDepth = errors.New("max depth limit reached")
2525
// ErrForbiddenURL is the error thrown if visiting
2626
// a URL which is not allowed by URLFilters
27-
ErrForbiddenURL = errors.New("ForbiddenURL")
27+
ErrForbiddenURL = errors.New("forbidden URL")
2828

2929
// ErrRobotsTxtBlocked is the error type for robots.txt errors
3030
ErrRobotsTxtBlocked = errors.New("URL blocked by robots.txt")
3131
// ErrEmptyProxyURL is the error type for empty Proxy URL list
32-
ErrEmptyProxyURL = errors.New("Proxy URL list is empty")
32+
ErrEmptyProxyURL = errors.New("proxy URL list is empty")
3333
// ErrAbortedAfterHeaders is the error returned when OnResponseHeaders aborts the transfer.
34-
ErrAbortedAfterHeaders = errors.New("Aborted after receiving response headers")
34+
ErrAbortedAfterHeaders = errors.New("aborted after receiving response headers")
3535
)

internal/collector/util.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)