Created
February 22, 2014 16:20
-
-
Save hiroakis/9157408 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net/http" | |
//"io/ioutil" | |
) | |
func get(url string, c chan bool){ | |
resp, err := http.Get(url) | |
if err != nil { | |
log.Print("error occurred") | |
} | |
defer resp.Body.Close() | |
//body, err := ioutil.ReadAll(resp.Body) | |
//if err != nil { | |
// log.Print("error occurred") | |
//} | |
//printResult(url, string(body)) | |
printResult(url, resp.Status) | |
c <- true | |
} | |
func printResult(url string, result string){ | |
log.Printf("result: %s, url: %s", result, url) | |
} | |
func main(){ | |
urls := []string{ | |
"https://hiroakis.com/blog/", | |
"http://www.yahoo.co.jp/", | |
"https://www.google.co.jp/", | |
"https://github.com/", | |
"http://ameblo.jp/", | |
"http://www.youtube.com/", | |
"https://twitter.com/", | |
"http://d.hatena.ne.jp/rx7/", | |
"http://d.hatena.ne.jp/oranie/", | |
"http://d.hatena.ne.jp/akuwano/", | |
"http://d.hatena.ne.jp/fat47/", | |
} | |
c := make(chan bool) | |
for _, v := range urls { | |
go get(v, c) | |
} | |
for i := 0; i < len(urls); i++ { | |
<-c | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment