title: How do I use the .Read function in Go?
body: <p>Trying to use Go's http package, I can't work out the syntax of <code>.Read</code>. The following marked by HERE is the only thing I have got to compile, although I tried several other things which were all rejected by the compiler.</p>
  
  <pre><code>package main
  import "fmt";
  import "http";
  import "os";
  
  func main () {
      kinopiko_flair := "http://stackoverflow.com/users/flair/181548.json";
      response, _, error := http.Get (kinopiko_flair);
      if (error != nil) {
          // I want to print out the error too.
          fmt.Printf ("Error getting %s\n", kinopiko_flair);
          os.Exit (1);
      }
      fmt.Printf ("Status is %s\n", response.Status);
      var nr int;
      var buf []byte;
      nr, error = response.Body.Read (buf); // HERE
      if (error != nil) {
          // I want to print out the error too.
          fmt.Printf ("Error reading response.\n");
          os.Exit (1);
      }
      response.Body.Close ();
      fmt.Printf ("Got %d bytes\n", nr);
      fmt.Printf ("Got '%s'\n", buf);
  }
  </code></pre>
  
  <p>The URL is OK, since <code>wget</code> gets it fine, but when I run this <code>buf</code> is just an empty string and <code>nr</code> is always zero. What do I need to do to get the data out of <code>response</code>? The compiler rejected <code>.ReadAll</code> and other things I tried.</p>
  
  <p>The output looks like this:</p>
  
  <pre>
  Status is 200 OK
  Got 0 bytes
  Got ''
  </pre>