Skip to content

Instantly share code, notes, and snippets.

@anonrose
Last active March 30, 2016 05:46
Show Gist options
  • Save anonrose/6994194031ec241c2e6690020cec011e to your computer and use it in GitHub Desktop.
Save anonrose/6994194031ec241c2e6690020cec011e to your computer and use it in GitHub Desktop.
http.Get example in Golang, the other one is out of date and won't let me submit pulls
package main
import (
"fmt"
"net/http"
"io/ioutil"
"os"
)
func main() {
response, err := http.Get("http://golang.org/")
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Printf("%s\n", string(contents))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment