Specifically check for timeout error
特异性识别 golang http client 的超时错误
1 package main 2 3 import ( 4 "fmt" 5 "net" 6 "net/http" 7 ) 8 9 func main() { 10 client := &http.Client{} 11 _, err := client.Get("http://lsjkgj/kllsjkljg/jljsdglk") 12 13 fmt.Println(err.Error()) 14 15 if oe, ok := err.(net.Error); ok { 16 if oe.Timeout() { 17 fmt.Println("timeout") 18 } 19 } else { 20 fmt.Println("error") 21 } 22 }
Get http://lsjkgj/kllsjkljg/jljsdglk: dial tcp: i/o timeout timeout
有疑问加站长微信联系(非本文作者)