Skip to content

Instantly share code, notes, and snippets.

@quii
Created March 20, 2015 10:51
Show Gist options
  • Save quii/913d27d87e9a430acc2c to your computer and use it in GitHub Desktop.
Save quii/913d27d87e9a430acc2c to your computer and use it in GitHub Desktop.
// 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 func() {
helloResponse, _ := http.Get(helloURL)
defer helloResponse.Body.Close()
helloContent, _ := ioutil.ReadAll(helloResponse.Body)
helloChannel <- helloContent
}()
go func() {
worldResponse, _ := http.Get(worldURL)
defer worldResponse.Body.Close()
worldContent, _ := ioutil.ReadAll(worldResponse.Body)
worldChannel <- worldContent
}()
return string(<-helloChannel) + ", " + string(<-worldChannel)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment