1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | package concurrenthttprequests import ( "io/ioutil" "log" "net/http" ) type Url string type Urls []Url type HttpResponse struct { url string response *http.Response body string err error } func NewQueue(args ...string) (urls Urls) { for _, arg := range args { urls = append(urls, Url(arg)) } return } func (url Url) ToString() string { return string(url) } func (url Url) get(ch chan HttpResponse) { resp, err := http.Get(url.ToString()) if err != nil { log.Fatal(err) } body, err := ioutil.ReadAll(resp.Body) resp.Body.Close() if err != nil { log.Fatal(err) } ch <- HttpResponse{ url: url.ToString(), response: resp, body: string(body), err: err, } } func (urls Urls) Get() (resp []string) { ch := make(chan HttpResponse) for _, url := range urls { go url.get(ch) } for _, _ = range urls { resp = append(resp, (<-ch).body) } return } | cs |
쉬,,,벌,,, 조옷나 빠르다아이가,,,
http://lgstar.tk
커뮤니티 사이트 입니다 많은 이용 부탁 드립니다. - DCW