From 2e3bd184308bc058b55395ed652602bf7dfcc984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Musab=20G=C3=BCltekin?= Date: Sat, 8 Jun 2019 20:27:45 +0300 Subject: [PATCH] Options refactored to its own file. Timeout increased to 60 sec --- README.md | 3 --- geziyor.go | 10 +--------- options.go | 21 +++++++++++++++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 options.go diff --git a/README.md b/README.md index 5fd378f..0c2d6c6 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,6 @@ geziyor := NewGeziyor(Opt{ r.Exports <- map[string]interface{}{ "text": s.Find("span.text").Text(), "author": s.Find("small.author").Text(), - "tags": s.Find("div.tags > a.tag").Map(func(_ int, s *goquery.Selection) string { - return s.Text() - }), } }) diff --git a/geziyor.go b/geziyor.go index 7e2811e..9e253e2 100644 --- a/geziyor.go +++ b/geziyor.go @@ -23,14 +23,6 @@ type Geziyor struct { visitedURLS []string } -// Options is custom options type for Geziyor -type Options struct { - AllowedDomains []string - StartURLs []string - ParseFunc func(response *Response) - Cache httpcache.Cache -} - func init() { log.SetOutput(os.Stdout) } @@ -40,7 +32,7 @@ func init() { func NewGeziyor(opt Options) *Geziyor { geziyor := &Geziyor{ client: &http.Client{ - Timeout: time.Second * 10, + Timeout: time.Second * 60, }, opt: opt, } diff --git a/options.go b/options.go new file mode 100644 index 0000000..cb06e95 --- /dev/null +++ b/options.go @@ -0,0 +1,21 @@ +package geziyor + +import ( + "github.com/fpfeng/httpcache" +) + +// Options is custom options type for Geziyor +type Options struct { + // AllowedDomains is domains that are allowed to make requests + // If empty, any domain is allowed + AllowedDomains []string + // First requests will made to this url array. (Concurrently) + StartURLs []string + // ParseFunc is callback of StartURLs response. + ParseFunc func(response *Response) + + // Set this to enable caching responses. + // Memory Cache: httpcache.NewMemoryCache() + // Disk Cache: diskcache.New(".cache") + Cache httpcache.Cache +}