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 {
|
type LinkChecker struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
visited map[string]bool
|
visited map[string]bool
|
||||||
|
pagesChecked int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLinkChecker() *LinkChecker {
|
func NewLinkChecker() *LinkChecker {
|
||||||
return &LinkChecker{
|
return &LinkChecker{
|
||||||
client: &http.Client{},
|
client: &http.Client{},
|
||||||
visited: make(map[string]bool),
|
visited: make(map[string]bool),
|
||||||
|
pagesChecked: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +52,9 @@ func (lc *LinkChecker) checkLinksRecursive(pageURL string, brokenLinks []BrokenL
|
||||||
return brokenLinks, nil
|
return brokenLinks, nil
|
||||||
}
|
}
|
||||||
lc.visited[pageURL] = true
|
lc.visited[pageURL] = true
|
||||||
|
lc.pagesChecked++
|
||||||
|
|
||||||
|
fmt.Printf("Checking page %d: %s\n", lc.pagesChecked, pageURL)
|
||||||
|
|
||||||
links, err := lc.getLinks(pageURL)
|
links, err := lc.getLinks(pageURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
4
main.go
4
main.go
|
@ -20,12 +20,14 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("\nTotal pages checked: %d\n\n", checker.pagesChecked)
|
||||||
|
|
||||||
if len(brokenLinks) == 0 {
|
if len(brokenLinks) == 0 {
|
||||||
fmt.Println("No broken links found!")
|
fmt.Println("No broken links found!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Found broken links:")
|
fmt.Printf("Found %d broken links:\n", len(brokenLinks))
|
||||||
for _, link := range brokenLinks {
|
for _, link := range brokenLinks {
|
||||||
if link.Error != "" {
|
if link.Error != "" {
|
||||||
fmt.Printf("- %s (Error: %s)\n", link.URL, link.Error)
|
fmt.Printf("- %s (Error: %s)\n", link.URL, link.Error)
|
||||||
|
|
Loading…
Reference in New Issue