feat: Add progress tracking and page checking information to link checker
This commit is contained in:
parent
7020dbd47d
commit
667d102277
|
@ -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 {
|
||||
|
|
4
main.go
4
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)
|
||||
|
|
Loading…
Reference in New Issue