Skip to content

Instantly share code, notes, and snippets.

@dipeshhkc
Last active June 28, 2023 20:43
Show Gist options
  • Save dipeshhkc/27ecd4f7c83e7d3ba9a0963a555dc816 to your computer and use it in GitHub Desktop.
Save dipeshhkc/27ecd4f7c83e7d3ba9a0963a555dc816 to your computer and use it in GitHub Desktop.
func main() {
c := make(chan string)
websites := []string{
"https://stackoverflow.com/",
"https://github.com/",
"https://www.linkedin.com/",
"http://medium.com/",
"https://golang.org/",
"https://www.udemy.com/",
"https://www.coursera.org/",
"https://wesionary.team/",
}
for _, website := range websites {
go getWebsite(website, c)
}
// Iterating over the range of channel. So keeps receiving messages until channel is closed
for range websites {
fmt.Println(<-c)
}
func getWebsite(website string, c chan string) {
if _, err := http.Get(website); err != nil {
c <- website + "is down"
} else {
c <- website + "is up"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment