package main
import (
"fmt"
"io/ioutil"
"net/http"
"time"
)
func main() {
length := 10
t1 := time.Now().Second()
ch := make(chan []byte,length)
//var w sync.WaitGroup
// 开启一个并发匿名函数
for i:=0;i<length;i++ {
go func() {
Res, _ :=http.Get("https://www.sina.com.cn/api/hotword.json")
content, _ := ioutil.ReadAll(Res.Body)
Res.Body.Close()
ch<-content
}()
}
for j:=0;j<length;j++{
fileName := fmt.Sprintf("./ach-sina-%d",j)
content := <-ch
fmt.Println(content)
ioutil.WriteFile(fileName,content,1)
}
t2 := time.Now().Second()
fmt.Printf("%d次请求,总共耗时%ds\n", length,t2-t1)
fmt.Println("all done")
}