// Fetchall fetches URLs in parallel and reports their times and sizes.
for _, url := range os.Args[1:] {
go fetch(url, ch) // start a goroutine
fmt.Println(<-ch) // receive from channel ch
fmt.Printf("%.2fs elapsed\n", time.Since(start).Seconds())
func fetch(url string, ch chan<- string) {
resp, err := http.Get(url)
ch <- fmt.Sprint(err) // send to channel ch
nbytes, err := io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close() // don't leak resources
ch <- fmt.Sprintf("while reading %s: %v", url, err)
secs := time.Since(start).Seconds()
ch <- fmt.Sprintf("%.2fs %7d %s", secs, nbytes, url)