Skip to content

Commit

Permalink
Add RateLimitTransport to the client.Transport chain
Browse files Browse the repository at this point in the history
And enhance how the Transport are added

Signed-off-by: David Pordomingo <[email protected]>
  • Loading branch information
dpordomingo committed Oct 15, 2019
1 parent adf3a6b commit ad4fc20
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
3 changes: 1 addition & 2 deletions examples/cmd/logtransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions examples/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 0 additions & 10 deletions github/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit ad4fc20

Please sign in to comment.