Timeout support added
This commit is contained in:
parent
2e3bd18430
commit
f2fba85266
@ -40,6 +40,9 @@ func NewGeziyor(opt Options) *Geziyor {
|
|||||||
if opt.Cache != nil {
|
if opt.Cache != nil {
|
||||||
geziyor.client.Transport = httpcache.NewTransport(opt.Cache)
|
geziyor.client.Transport = httpcache.NewTransport(opt.Cache)
|
||||||
}
|
}
|
||||||
|
if opt.Timeout != 0 {
|
||||||
|
geziyor.client.Timeout = opt.Timeout
|
||||||
|
}
|
||||||
|
|
||||||
return geziyor
|
return geziyor
|
||||||
}
|
}
|
||||||
@ -92,6 +95,7 @@ func (g *Geziyor) Do(req *http.Request) {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Response error: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package geziyor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fpfeng/httpcache"
|
"github.com/fpfeng/httpcache"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options is custom options type for Geziyor
|
// Options is custom options type for Geziyor
|
||||||
@ -13,6 +14,8 @@ type Options struct {
|
|||||||
StartURLs []string
|
StartURLs []string
|
||||||
// ParseFunc is callback of StartURLs response.
|
// ParseFunc is callback of StartURLs response.
|
||||||
ParseFunc func(response *Response)
|
ParseFunc func(response *Response)
|
||||||
|
// Timeout is global request timeout
|
||||||
|
Timeout time.Duration
|
||||||
|
|
||||||
// Set this to enable caching responses.
|
// Set this to enable caching responses.
|
||||||
// Memory Cache: httpcache.NewMemoryCache()
|
// Memory Cache: httpcache.NewMemoryCache()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user