Skip to content

Commit

Permalink
Improve: use fetcher for core
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu committed Feb 14, 2024
1 parent 3345373 commit 700cd28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions common/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Config struct {
// Return error when status is not OK.
RaiseForStatus bool

// HTTP Request timeout.
Timeout time.Duration

// Custom HTTP Transport.
Transport http.RoundTripper
}
Expand Down Expand Up @@ -73,6 +76,9 @@ func Default(cfg *Config) *Fetcher {
CheckRetry: retryablehttp.DefaultRetryPolicy,
Backoff: retryablehttp.DefaultBackoff,
}
if cfg.Timeout > time.Second {
c.HTTPClient.Timeout = cfg.Timeout
}
if cfg.Transport != nil {
c.HTTPClient.Transport = cfg.Transport
}
Expand Down
10 changes: 7 additions & 3 deletions provider/1pondo/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ type Core struct {

func (core *Core) Init() *Core {
t := http.DefaultTransport.(*http.Transport).Clone()
t.MaxIdleConnsPerHost = 1000
t.IdleConnTimeout = 90 * time.Minute
t.MaxConnsPerHost = 5
t.MaxIdleConnsPerHost = 5
t.IdleConnTimeout = 5 * time.Minute

core.Fetcher = fetch.Default(&fetch.Config{Transport: t})
core.Fetcher = fetch.Default(&fetch.Config{
Transport: t,
Timeout: 15 * time.Second,
})
core.Scraper = scraper.NewDefaultScraper(core.DefaultName, core.BaseURL, core.DefaultPriority,
scraper.WithHeaders(map[string]string{
"Content-Type": "application/json",
Expand Down

0 comments on commit 700cd28

Please sign in to comment.