Created
May 3, 2021 22:20
-
-
Save harrisoncramer/0e8f0e7f83800380dc05379d2331f8e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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