Created
April 6, 2017 06:32
-
-
Save vbauerster/e341100158579b24ea5fc392ac1d09a0 to your computer and use it in GitHub Desktop.
This file contains 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" | |
"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