Created
July 16, 2020 08:12
-
-
Save dipeshhkc/57bcbd56a6886ead8d081f9a8c7b4785 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
var wg sync.WaitGroup | |
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 { | |
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