I\'m making a URL fetcher in Go and have a list of URLs to fetch. I send http.Get()
requests to each URL and obtain their response.
resp,fetch_e
You need to set up your own Client with your own Transport which uses a custom Dial function which wraps around DialTimeout.
Something like (completely untested) this:
var timeout = time.Duration(2 * time.Second)
func dialTimeout(network, addr string) (net.Conn, error) {
return net.DialTimeout(network, addr, timeout)
}
func main() {
transport := http.Transport{
Dial: dialTimeout,
}
client := http.Client{
Transport: &transport,
}
resp, err := client.Get("http://some.url")
}