Skip to content

Instantly share code, notes, and snippets.

@rogerwelin
Last active September 12, 2018 20:22
Show Gist options
  • Save rogerwelin/94fa6eaa413f7280f2bad9b595de9952 to your computer and use it in GitHub Desktop.
Save rogerwelin/94fa6eaa413f7280f2bad9b595de9952 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
"sync"
)
func main() {
urls := []string{"https://rogerwelin.github.io/",
"https://golang.org/",
"https://news.ycombinator.com/",
"https://www.google.se/shouldbe404",
"https://www.cpan.org/"}
respStatus := make(map[string]int)
var wg sync.WaitGroup
for _, url := range urls {
wg.Add(1)
go func(url string) {
defer wg.Done()
resp, err := http.Get(url)
if err != nil {
fmt.Errorf("url was error: %v", err)
}
respStatus[url] = resp.StatusCode
}(url)
}
wg.Wait()
for key, code := range respStatus {
fmt.Printf("%s -> %d\n", key, code)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment