Skip to content

Instantly share code, notes, and snippets.

@ii0
Forked from ijt/http_get.go
Created April 8, 2016 05:24
Show Gist options
  • Save ii0/3c7a9dad49e5c43237c444d3ac56de9d to your computer and use it in GitHub Desktop.
Save ii0/3c7a9dad49e5c43237c444d3ac56de9d to your computer and use it in GitHub Desktop.
Example of using http.Get in go (golang)
package main
import (
"fmt"
"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