Skip to content

Instantly share code, notes, and snippets.

@ashleyconnor
Created May 21, 2014 21:25
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 ashleyconnor/01db92d134405bfdbf60 to your computer and use it in GitHub Desktop.
Save ashleyconnor/01db92d134405bfdbf60 to your computer and use it in GitHub Desktop.
Go Getter - Go program that fetches a webpage and outputs to STDOUT
package main
import (
"fmt"
"net/http"
"io/ioutil"
"os"
)
func main() {
response, err := http.Get(os.Args[1])
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))
}
}
@ashleyconnor
Copy link
Author

Build:

go build go_getter.go

Run:

./go_getter http://www.google.com

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