Created
November 15, 2013 00:26
-
-
Save hatched/7476974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Small typo in L18 - in case somebody else finds it useful.
Thanks for posting this.