From 2e4b6abc07036df7a001b1b8305edc55f27dda9f Mon Sep 17 00:00:00 2001 From: demo Date: Thu, 28 May 2026 11:45:10 -0400 Subject: refactor: move html document creation to getBatch Also, if there are errors, I log them and simply return a nil slice. --- classic.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'classic.go') diff --git a/classic.go b/classic.go index 653f8f8..19450c1 100644 --- a/classic.go +++ b/classic.go @@ -1,11 +1,14 @@ package main import ( + "bytes" "context" "fmt" "log" "net/url" "sync" + + "golang.org/x/net/html" ) func classic(startURL url.URL, maxConcurrency, maxURLs, maxDepth int) { @@ -73,12 +76,19 @@ loop: } func getBatch(u url.URL) []url.URL { - doc, err := fetch(u) + htmlBytes, err := fetch(u) + if err != nil { + log.Print(err) + return nil + } + + htmlDoc, err := html.Parse(bytes.NewReader(htmlBytes)) if err != nil { log.Print(err) + return nil } - batch := findURLs(u, doc) + batch := findURLs(u, htmlDoc) return batch } -- cgit v1.2.3