Created
May 16, 2016 01:12
-
-
Save davidbirdsong/92dea0aa4a3722f8e20bab602e76155d to your computer and use it in GitHub Desktop.
go errors rarely do what i expect
This file contains hidden or 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/x509" | |
| "fmt" | |
| "net/http" | |
| ) | |
| func main() { | |
| if req, err := http.NewRequest("GET", "https://too.long.s3.amazonaws.com/index.html ", nil); err != nil { | |
| panic(err) | |
| } else if _, err = http.DefaultClient.Do(req); err != nil { | |
| if _, ok := err.(x509.HostnameError); ok { | |
| fmt.Println("i'm x509.HostnameError!") | |
| } else if _, ok = err.(x509.CertificateInvalidError); ok { | |
| fmt.Println("i'm x509.CertificateInvalidError") | |
| } else { | |
| panic(fmt.Errorf("WTF i can't be coerced into anything: %v!", err)) | |
| } | |
| } | |
| } |
Author
davidbirdsong
commented
May 16, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment