Created
January 17, 2015 15:31
-
-
Save aln787/62d21ddc1a709cb91241 to your computer and use it in GitHub Desktop.
Go Lang HTTP Get Example
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 ( | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
) | |
func checkErr(e error) { | |
if e != nil { | |
panic(e) | |
} | |
} | |
func main() { | |
res, err := http.Get("http://golang.org/pkg/net/http/") | |
checkErr(err) | |
defer res.Body.Close() | |
body, err := ioutil.ReadAll(res.Body) | |
checkErr(err) | |
fmt.Println(string(body)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment