Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.