From 667d102277753ecc21998012b7dc19862fa40537 Mon Sep 17 00:00:00 2001 From: "Erik Winter (aider)" Date: Mon, 25 Nov 2024 09:54:28 +0100 Subject: [PATCH] feat: Add progress tracking and page checking information to link checker --- linkchecker.go | 15 ++++++++++----- main.go | 4 +++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/linkchecker.go b/linkchecker.go index 7d08b80..992ffe2 100644 --- a/linkchecker.go +++ b/linkchecker.go @@ -10,14 +10,16 @@ import ( ) type LinkChecker struct { - client *http.Client - visited map[string]bool + client *http.Client + visited map[string]bool + pagesChecked int } func NewLinkChecker() *LinkChecker { return &LinkChecker{ - client: &http.Client{}, - visited: make(map[string]bool), + client: &http.Client{}, + visited: make(map[string]bool), + pagesChecked: 0, } } @@ -50,7 +52,10 @@ 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 { return nil, fmt.Errorf("error getting links: %w", err) diff --git a/main.go b/main.go index 02be82c..f44a3dc 100644 --- a/main.go +++ b/main.go @@ -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)