Skip to content

Instantly share code, notes, and snippets.

@andreagrandi
Created August 21, 2014 15:17
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 andreagrandi/8dd30a82a89d7561f376 to your computer and use it in GitHub Desktop.
Save andreagrandi/8dd30a82a89d7561f376 to your computer and use it in GitHub Desktop.
http.get() example to get a remote url and display its content
package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
)
var url = flag.String("u", "", "URL to read")
func main() {
flag.Parse()
resp, err := http.Get(*url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
content, err := ioutil.ReadAll(resp.Body)
fmt.Println(string(content))
}
@andreagrandi
Copy link
Author

Example: go run get_client.go -u http://www.google.it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment