// Fetchall fetches URLs in parallel and reports their times and sizes.packagemainimport("fmt""io""io/ioutil""net/http""os""time")funcmain(){start:=time.Now()ch:=make(chanstring)for_,url:=rangeos.Args[1:]{gofetch(url,ch)// start a goroutine}forrangeos.Args[1:]{fmt.Println(<-ch)// receive from channel ch}fmt.Printf("%.2fs elapsed\n",time.Since(start).Seconds())}funcfetch(urlstring,chchan<-string){start:=time.Now()resp,err:=http.Get(url)iferr!=nil{ch<-fmt.Sprint(err)// send to channel chreturn}nbytes,err:=io.Copy(ioutil.Discard,resp.Body)resp.Body.Close()// don't leak resourcesiferr!=nil{ch<-fmt.Sprintf("while reading %s: %v",url,err)return}secs:=time.Since(start).Seconds()ch<-fmt.Sprintf("%.2fs %7d%s",secs,nbytes,url)}