diff --git a/geziyor.go b/geziyor.go index 9e253e2..49b5578 100644 --- a/geziyor.go +++ b/geziyor.go @@ -40,6 +40,9 @@ func NewGeziyor(opt Options) *Geziyor { if opt.Cache != nil { geziyor.client.Transport = httpcache.NewTransport(opt.Cache) } + if opt.Timeout != 0 { + geziyor.client.Timeout = opt.Timeout + } return geziyor } @@ -92,6 +95,7 @@ func (g *Geziyor) Do(req *http.Request) { defer resp.Body.Close() } if err != nil { + log.Printf("Response error: %v\n", err) return } diff --git a/options.go b/options.go index cb06e95..59f1443 100644 --- a/options.go +++ b/options.go @@ -2,6 +2,7 @@ package geziyor import ( "github.com/fpfeng/httpcache" + "time" ) // Options is custom options type for Geziyor @@ -13,6 +14,8 @@ type Options struct { StartURLs []string // ParseFunc is callback of StartURLs response. ParseFunc func(response *Response) + // Timeout is global request timeout + Timeout time.Duration // Set this to enable caching responses. // Memory Cache: httpcache.NewMemoryCache()