Skip to content

Instantly share code, notes, and snippets.

@decebal
Forked from ijt/http_get.go
Last active April 13, 2016 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decebal/c910cd99f2a8772672c45e379449474b to your computer and use it in GitHub Desktop.
Save decebal/c910cd99f2a8772672c45e379449474b 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.Println( err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(string(contents))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment