title: How to pipe an HTTP response to a file in Go?
body: <p>How do I convert the below code to use streams/pipes so that I don't need to read the full content into memory?
  Something like:
  <code>http.Get("http://example.com/").Pipe("./data.txt")</code></p>
  
  <pre><code>package main
  import ("net/http";"io/ioutil")
  
  func main() {
          resp, err := http.Get("http://example.com/")
          check(err)
          defer resp.Body.Close()
          body, err := ioutil.ReadAll(resp.Body)
          check(err)
          err = ioutil.WriteFile("./data.txt", body, 0666)
          check(err)
  }
  func check(e error) {
          if e != nil {
                  panic(e)
          }
  }
  </code></pre>