Skip to content

Instantly share code, notes, and snippets.

@stereosteve
Forked from ijt/http_get.go
Last active December 14, 2015 09:29
Show Gist options
  • Save stereosteve/5064935 to your computer and use it in GitHub Desktop.
Save stereosteve/5064935 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"net/http"
"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