Created
June 1, 2018 15:20
-
-
Save nakamkaz/328dc88eab58c97f7329a17869569601 to your computer and use it in GitHub Desktop.
myhead - http.Head with golang
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 ( | |
"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