Skip to content

Instantly share code, notes, and snippets.

@dipeshhkc
Created July 16, 2020 08:16
Show Gist options
  • Save dipeshhkc/1fa7cd094632c9c107fe5f92f17dc4f2 to your computer and use it in GitHub Desktop.
Save dipeshhkc/1fa7cd094632c9c107fe5f92f17dc4f2 to your computer and use it in GitHub Desktop.
var wg sync.WaitGroup
var mut sync.Mutex
func main() {
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)
wg.Add(1)
}
wg.Wait()
}
func getWebsite(website string) {
defer wg.Done()
if res, err := http.Get(website); err != nil {
fmt.Println(website, "is down")
} else {
mut.Lock()
defer mut.Unlock()
fmt.Printf("[%d] %s is up\n", res.StatusCode, website)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment