feat: Add progress tracking and page checking information to link checker

This commit is contained in:
Erik Winter (aider) 2024-11-25 09:54:28 +01:00
parent 7020dbd47d
commit 667d102277
2 changed files with 13 additions and 6 deletions

View File

@ -12,12 +12,14 @@ import (
type LinkChecker struct {
client *http.Client
visited map[string]bool
pagesChecked int
}
func NewLinkChecker() *LinkChecker {
return &LinkChecker{
client: &http.Client{},
visited: make(map[string]bool),
pagesChecked: 0,
}
}
@ -50,6 +52,9 @@ func (lc *LinkChecker) checkLinksRecursive(pageURL string, brokenLinks []BrokenL
return brokenLinks, nil
}
lc.visited[pageURL] = true
lc.pagesChecked++
fmt.Printf("Checking page %d: %s\n", lc.pagesChecked, pageURL)
links, err := lc.getLinks(pageURL)
if err != nil {

View File

@ -20,12 +20,14 @@ func main() {
log.Fatal(err)
}
fmt.Printf("\nTotal pages checked: %d\n\n", checker.pagesChecked)
if len(brokenLinks) == 0 {
fmt.Println("No broken links found!")
return
}
fmt.Println("Found broken links:")
fmt.Printf("Found %d broken links:\n", len(brokenLinks))
for _, link := range brokenLinks {
if link.Error != "" {
fmt.Printf("- %s (Error: %s)\n", link.URL, link.Error)