mozillazg / request

A developer-friendly HTTP request library for Gopher.
https://godoc.org/github.com/mozillazg/request
MIT License
426 stars 40 forks source link

Cannot set timeout for request or any other method #11

Open jkryanchou opened 9 years ago

mozillazg commented 9 years ago

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
jkryanchou commented 9 years ago

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

jkryanchou commented 9 years ago

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