Skip to content

Instantly share code, notes, and snippets.

@shawnsmithdev
Last active July 16, 2017 06:59
Show Gist options
  • Save shawnsmithdev/cf5458b995c9507bc048f6ca2ba60727 to your computer and use it in GitHub Desktop.
Save shawnsmithdev/cf5458b995c9507bc048f6ca2ba60727 to your computer and use it in GitHub Desktop.
CLI tool that prints the HTTP HEAD response for an url
package main
import (
"fmt"
"net/http"
"net/http/httputil"
"os"
)
const defaultUrl = "https://example.com"
func main() {
url := defaultUrl
if len(os.Args) < 2 {
fmt.Println("Missing argument: url to head, using ", defaultUrl)
} else {
url = os.Args[1]
}
resp, err := http.Head(url)
if hasErr(err) {
return
}
defer resp.Body.Close()
dump, err := httputil.DumpResponse(resp, false)
if hasErr(err) {
return
}
fmt.Printf("%s", dump)
}
func hasErr(err error) bool {
erred := err != nil
if erred {
fmt.Println("Couldn't do it", err)
}
return erred
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment