http - How to check if error is tls handshake timeout in Go -


i have following code making request url , checking errors.

import "net/http"  response, err := http.head("url") 

how check if error due tls handshake timeout? tried following:

if err != nil {     tlserror, ok := err.(http.tlshandshaketimeouterror)     if ok {         // handle error     } } 

but cannot access http.tlshandshaketimeouterror type because unexported. how else can check error type in go?

yes tlshandshaketimeouterror - not exported , 1 possibility check on error is:

import "net/url"  // ....  if urlerror,ok :=  err.(*url.error)  ; ok {     if urlerror.error() == "net/http: tls handshake timeout" {         // handle error     } } 

here open ticket discussion it:

https://github.com/golang/go/issues/15935

by way http errors (and tlshandshaketimeouterror also) provide also:

type withtimeout interface {    timeout() bool } 

you can use check if don't string comparsion. here example of istemporary implementation http2 package.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -