Skip to content

Instantly share code, notes, and snippets.

@hatched
Created November 15, 2013 00:26
Show Gist options
  • Save hatched/7476974 to your computer and use it in GitHub Desktop.
Save hatched/7476974 to your computer and use it in GitHub Desktop.
package main
import (
"io"
"log"
"net/http"
"os"
)
func main() {
resp, err := http.Get("http://reddit.com/r/golang.json")
if err != nil {
log.Fatal(err) // Logs to stderr
}
if resp.StatusCode != http.StatusOK { // If statusCode isn't a 2XX
log.Fatal(resp.Status) // Logs to stderr
}
io.Copy(os.Stdout, resp.body)
}
@heyalexej
Copy link

Small typo in L18 - in case somebody else finds it useful.

io.Copy(os.Stdout, resp.Body)

Thanks for posting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment