Skip to content

Instantly share code, notes, and snippets.

@rlorca
Last active December 17, 2015 22:19
Show Gist options
  • Save rlorca/5681665 to your computer and use it in GitHub Desktop.
Save rlorca/5681665 to your computer and use it in GitHub Desktop.
package main
import ("fmt"
"net/http")
type Endpoint struct {
address string
code int
}
func main() {
sites := []string{"http://uol.com.br", "http://google.com",
"http://github.com", "http://gist.github.com/lorchaos/5681665",
"http://invalid-address.copp"}
ch := make(chan *Endpoint, 100)
for _, site := range sites {
go request(site, ch)
}
for {
select {
case reply := <- ch :
fmt.Printf("%s -> %d\n", reply.address, reply.code)
}
}
}
func request(address string, ch chan *Endpoint) {
resp, err := http.Get(address)
status := -1
if (err == nil) {
status = resp.StatusCode
}
ch <- &Endpoint{address, status}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment