request icon indicating copy to clipboard operation
request copied to clipboard

Cannot set timeout for request or any other method

Open jkryanchou opened this issue 8 years ago • 3 comments

jkryanchou avatar Jul 11 '15 14:07 jkryanchou

You can set timeout with:

c := new(http.Client)

timeout := time.Duration(1 * time.Second)
c.Timeout = timeout

req := request.NewRequest(c)
req.Get(url)

or

timeout := time.Duration(1 * time.Second)
c := &http.Client{
  Timeout: timeout
}

req := request.NewRequest(c)
req.Get(url)

There is an example here: timeout.go

$ go run timeout.go 
default timeout
21.030151555
set timeout = 1.000000 seconds
1.0007582

mozillazg avatar Jul 12 '15 06:07 mozillazg

Great, I'm very appreciated for your answer :+1:

jkryanchou avatar Jul 15 '15 00:07 jkryanchou

I think it's better to be added into to the godoc : )

jkryanchou avatar Jul 15 '15 00:07 jkryanchou