I use the following to check for timeouts when calling a webservice, but I would like to check specifically if there is a timeout error returned. How do I do that :S
I have this:
// Timeout
type Timeout struct {
Connect time.Duration
ReadWrite time.Duration
}
// TimeoutDialer
func TimeoutDialer(timeout *Timeout) func(net, addr string) (c net.Conn, err error) {
return func(netw, addr string) (net.Conn, error) {
conn, err := net.DialTimeout(netw, addr, timeout.Connect)
if err != nil {
return nil, err
}
conn.SetDeadline(time.Now().Add(timeout.ReadWrite))
return conn, nil
}
}
// HttpClient
func HttpClient(config Config) *http.Client {
to := &Timeout{
Connect: time.Duration(config.MaxWait) * time.Second,
ReadWrite: time.Duration(config.MaxWait) * time.Second,
}
return &http.Client{
Transport: &http.Transport{
Dial: TimeoutDialer(to),
},
}
}