Skip to content

Instantly share code, notes, and snippets.

@quii
Created March 20, 2015 11:11
Show Gist options
  • Save quii/19480e075f276addc561 to your computer and use it in GitHub Desktop.
Save quii/19480e075f276addc561 to your computer and use it in GitHub Desktop.
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