Skip to content

Instantly share code, notes, and snippets.

@harrisoncramer
Created May 3, 2021 22:20
Show Gist options
  • Save harrisoncramer/0e8f0e7f83800380dc05379d2331f8e8 to your computer and use it in GitHub Desktop.
Save harrisoncramer/0e8f0e7f83800380dc05379d2331f8e8 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
)
func main() {
links := []string{
"http://google.com",
"http://facebook.com",
"http://stackoverflow.com",
"http://golang.org",
"http://amazon.com",
}
c := make(chan string)
for _, link := range links {
go checkLink(link, c)
}
// When the function completes, schedule a new go routine
// Pass the link into the function.
for l := range c {
go checkLink(l, c)
}
}
func checkLink(link string, c chan string) {
_, err := http.Get(link)
if err != nil {
log.Println(link, "is down!")
c <- link
return
}
log.Println(link, "is doing fine")
c <- link
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment