Last active
September 12, 2018 20:22
-
-
Save rogerwelin/94fa6eaa413f7280f2bad9b595de9952 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
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