Created
March 20, 2015 11:11
-
-
Save quii/19480e075f276addc561 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
const wordSeparator = ", " | |
// Stitcher calls the Hello and World APIs to create a very useful string | |
func Stitcher(helloURL string, worldURL string) string { | |
helloChannel := make(chan []byte, 1) | |
worldChannel := make(chan []byte, 1) | |
go getStringFromAPI(helloChannel, helloURL) | |
go getStringFromAPI(worldChannel, worldURL) | |
return string(<-helloChannel) + wordSeparator + string(<-worldChannel) | |
} | |
func getStringFromAPI(ch chan<- []byte, url string) { | |
response, _ := http.Get(url) | |
defer response.Body.Close() | |
content, _ := ioutil.ReadAll(response.Body) | |
ch <- content | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment