refactor: Separate redirects and broken links into distinct output sections
This commit is contained in:
parent
3f7cde44a2
commit
99b458e40a
37
main.go
37
main.go
|
@ -23,18 +23,41 @@ func main() {
|
||||||
fmt.Printf("\nTotal pages checked: %d\n\n", checker.pagesChecked)
|
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 issues found!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Found %d issues:\n", len(brokenLinks))
|
// First list redirects
|
||||||
|
var redirectCount int
|
||||||
for _, link := range brokenLinks {
|
for _, link := range brokenLinks {
|
||||||
if link.Error != "" {
|
if link.Redirect != nil {
|
||||||
fmt.Printf("- %s (Error: %s)\n", link.URL, link.Error)
|
if redirectCount == 0 {
|
||||||
} else if link.Redirect != nil {
|
fmt.Println("Redirects found:")
|
||||||
|
}
|
||||||
fmt.Printf("- %s (Redirect %d -> %s)\n", link.URL, link.StatusCode, link.Redirect.ToURL)
|
fmt.Printf("- %s (Redirect %d -> %s)\n", link.URL, link.StatusCode, link.Redirect.ToURL)
|
||||||
} else {
|
redirectCount++
|
||||||
fmt.Printf("- %s (Status: %d)\n", link.URL, link.StatusCode)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if redirectCount > 0 {
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then list broken links
|
||||||
|
var brokenCount int
|
||||||
|
for _, link := range brokenLinks {
|
||||||
|
if link.Redirect == nil {
|
||||||
|
if brokenCount == 0 {
|
||||||
|
fmt.Println("Broken links found:")
|
||||||
|
}
|
||||||
|
if link.Error != "" {
|
||||||
|
fmt.Printf("- %s (Error: %s)\n", link.URL, link.Error)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("- %s (Status: %d)\n", link.URL, link.StatusCode)
|
||||||
|
}
|
||||||
|
brokenCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("\nTotal issues: %d (%d redirects, %d broken)\n",
|
||||||
|
len(brokenLinks), redirectCount, brokenCount)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue