Last active
December 17, 2015 22:19
-
-
Save rlorca/5681665 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ("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