Skip to content

Instantly share code, notes, and snippets.

@hiroakis
Created February 22, 2014 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiroakis/9157408 to your computer and use it in GitHub Desktop.
Save hiroakis/9157408 to your computer and use it in GitHub Desktop.
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