Last active
June 28, 2023 20:43
-
-
Save dipeshhkc/27ecd4f7c83e7d3ba9a0963a555dc816 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
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