package main import ( "net/http" "sync" ) func main() { var wg sync.WaitGroup var urls = []string{ "http://www.baidu.com/", "http://www.somestupidname.com/", } for _, url := range urls { // 添加WaitGroup 计数器. wg.Add(1) // 运行一个协程去获取 URL. go func(url string) { // 当协程结束时,计数器减一 defer wg.Done() // 获取 URL. http.Get(url) }(url) } // 等待所有url获取完成 wg.Wait() }