Created
July 16, 2020 08:16
-
-
Save dipeshhkc/1fa7cd094632c9c107fe5f92f17dc4f2 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 | |
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