Skip to content

Instantly share code, notes, and snippets.

@ngurajeka
Last active May 22, 2020 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngurajeka/4f4ee2c054b38512dc6d3198910e5cfa to your computer and use it in GitHub Desktop.
Save ngurajeka/4f4ee2c054b38512dc6d3198910e5cfa to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
"sync"
)
func main() {
urls := []string{
"https://github.com",
"https://api.github.com",
"https://google.com",
"https://ngurajeka.com",
"https://meraxes.id",
"https://valutac.com",
"https://teams.microsoft.com",
"https://facebook.com",
"https://twitter.com",
}
var wg sync.WaitGroup
for _, url := range urls {
wg.Add(1)
go func(v string) {
defer wg.Done()
resp, err := http.Get(v)
if err != nil {
log.Printf("%s got err: %s", v, err.Error())
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
log.Printf("%s get error code: %d", v, resp.StatusCode)
return
}
log.Printf("%s looks fine", v)
}(url)
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment