Skip to content

Instantly share code, notes, and snippets.

@nakamkaz
Created June 1, 2018 15:20
Show Gist options
  • Save nakamkaz/328dc88eab58c97f7329a17869569601 to your computer and use it in GitHub Desktop.
Save nakamkaz/328dc88eab58c97f7329a17869569601 to your computer and use it in GitHub Desktop.
myhead - http.Head with golang
package main
import (
"crypto/tls"
"fmt"
"log"
"net/http"
"os"
)
func main() {
if len(os.Args) <= 0 {
log.Println("URLが必要")
panic(os.Args)
}
url := os.Args[1]
callHead(url)
}
func callHead(url string) {
request, _ := http.NewRequest("HEAD", url, nil)
trans := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{
Transport: trans,
}
resp, err := client.Do(request)
if err != nil {
log.Println(err)
os.Exit(1)
}
for name, value := range resp.Header {
fmt.Printf("%v: %v\n", name, value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment