From ad4fc20ec553d64448dbf3612a9a6317f2879836 Mon Sep 17 00:00:00 2001 From: David Pordomingo Date: Tue, 15 Oct 2019 13:50:00 +0200 Subject: [PATCH] Add RateLimitTransport to the client.Transport chain And enhance how the Transport are added Signed-off-by: David Pordomingo --- examples/cmd/logtransport.go | 3 +-- examples/cmd/main.go | 3 +++ github/downloader.go | 10 ---------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/examples/cmd/logtransport.go b/examples/cmd/logtransport.go index bb2be9e..6c8e2d0 100644 --- a/examples/cmd/logtransport.go +++ b/examples/cmd/logtransport.go @@ -10,8 +10,7 @@ import ( ) func setLogTransport(client *http.Client, logger log.Logger) { - t := &logTransport{client.Transport, logger} - client.Transport = t + client.Transport = &logTransport{client.Transport, logger} } type logTransport struct { diff --git a/examples/cmd/main.go b/examples/cmd/main.go index 69a1e13..1023e5a 100644 --- a/examples/cmd/main.go +++ b/examples/cmd/main.go @@ -270,6 +270,9 @@ func (c *DownloaderCmd) buildDownloadersPool(logger log.Logger, db *sql.DB) (*Do setLogTransport(client, logger) } + github.SetRateLimitTransport(client, logger) + github.SetRetryTransport(client) + var d *github.Downloader var err error if db == nil { diff --git a/github/downloader.go b/github/downloader.go index f692acb..90c2839 100644 --- a/github/downloader.go +++ b/github/downloader.go @@ -58,11 +58,6 @@ type Downloader struct { // in the given DB. The HTTP client is expected to have the proper // authentication setup func NewDownloader(httpClient *http.Client, db *sql.DB) (*Downloader, error) { - // TODO: is the ghsync rate limited client needed? - - t := &retryTransport{httpClient.Transport} - httpClient.Transport = t - return &Downloader{ storer: &store.DB{DB: db}, client: githubv4.NewClient(httpClient), @@ -73,11 +68,6 @@ func NewDownloader(httpClient *http.Client, db *sql.DB) (*Downloader, error) { // metadata to stdout. The HTTP client is expected to have the proper // authentication setup func NewStdoutDownloader(httpClient *http.Client) (*Downloader, error) { - // TODO: is the ghsync rate limited client needed? - - t := &retryTransport{httpClient.Transport} - httpClient.Transport = t - return &Downloader{ storer: &store.Stdout{}, client: githubv4.NewClient(httpClient),