mirror of
https://github.com/NotAShelf/mdlinkt.git
synced 2024-11-22 21:31:09 +00:00
null check for http.Head response
This commit is contained in:
parent
e5e16be391
commit
50298ea412
1 changed files with 14 additions and 15 deletions
7
main.go
7
main.go
|
@ -62,10 +62,10 @@ func main() {
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
link := strings.TrimSpace(match[2])
|
link := strings.TrimSpace(match[2])
|
||||||
resp, err := http.Head(link)
|
resp, err := http.Head(link)
|
||||||
isInvalid := err != nil || resp.StatusCode == http.StatusNotFound || strings.Contains(err.Error(), "no such host")
|
if err != nil {
|
||||||
if isInvalid {
|
|
||||||
logWithColor("ERROR", "Invalid link: %s", link)
|
logWithColor("ERROR", "Invalid link: %s", link)
|
||||||
} else {
|
continue
|
||||||
|
}
|
||||||
result := LinkCheckResult{
|
result := LinkCheckResult{
|
||||||
Link: link,
|
Link: link,
|
||||||
IsValid: resp.StatusCode == http.StatusOK,
|
IsValid: resp.StatusCode == http.StatusOK,
|
||||||
|
@ -81,7 +81,6 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
logWithColor("ERROR", "Error scanning file: %v", err)
|
logWithColor("ERROR", "Error scanning file: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue