From f2fba852660104feb4ce7108f127b54b65eb9f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Musab=20G=C3=BCltekin?= Date: Sat, 8 Jun 2019 20:36:11 +0300 Subject: [PATCH] Timeout support added --- geziyor.go | 4 ++++ options.go | 3 +++ 2 files changed, 7 insertions(+) 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()