Skip to content

Instantly share code, notes, and snippets.

@vbauerster
Created April 6, 2017 06:32
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vbauerster/e341100158579b24ea5fc392ac1d09a0 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
responses := make(chan string, 3)
go func() { responses <- request("http://asia.gopl.io") }()
go func() { responses <- request("http://europe.gopl.io") }()
go func() { responses <- request("http://americas.gopl.io") }()
fmt.Println(<-responses)
}
func request(hostname string) string {
res, err := http.Get(hostname)
if err != nil {
return fmt.Sprintln(err)
}
defer res.Body.Close()
content, err := ioutil.ReadAll(res.Body)
if err != nil {
return fmt.Sprintln(err)
}
return string(content)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment