Skip to content

Commit

Permalink
Better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
melvinsh committed Aug 21, 2022
1 parent ed15344 commit 75d8c77
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@ func main() {
}

for _, url := range urls {
fmt.Println(host(url))
host := host(url)

if host == "" {
fmt.Fprintln(os.Stderr, "Cannot parse as URL: "+url)
continue
}

fmt.Println(host)
}
}

func host(u string) string {
parsed, err := url.Parse(u)

if err != nil {
return u
fmt.Fprintln(os.Stderr, err)
return ""
}

return parsed.Host
Expand Down

0 comments on commit 75d8c77

Please sign in to comment.