go 多个协程访问

package main

import (
   "fmt"
   "io/ioutil"
   "net/http"
   "time"
)
func main()  {
   for{
      for i:=0;i<10;i++{
         go request("http://baidu.com")
      }
      time.Sleep(time.Second)
   }
}
func request(url string)  {
   req:=http.Client{Timeout: 20 * time.Second}
   res,err:=req.Get(url)
   if err!=nil{
      panic("什么鬼错误哦")
   }
   defer res.Body.Close()
   body, err := ioutil.ReadAll(res.Body)
   fmt.Println([]byte(body))
}

你可能感兴趣的:(golang)