Skip to content

A GoLang HTTP RoundTripper that handles GitHub API secondary rate limits

License

Notifications You must be signed in to change notification settings

zendesk-piotrpawluk/go-github-ratelimit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-github-ratelimit

Go Report Card

Package go-github-ratelimit provides a http.RoundTripper implementation that handles secondary rate limit for the GitHub API.
The RoundTripper waits for the secondary rate limit to finish in a blocking mode and then issues/retries requests.

go-github-ratelimit can be used with any HTTP client communicating with GitHub API.
It is meant to complement go-github, but there is no association between this repository and the go-github repository or Google.

Installation

go get github.com/gofri/go-github-ratelimit

Usage Example (with go-github and oauth2)

import "github.com/google/go-github/github"
import "golang.org/x/oauth2"
import "github.com/gofri/go-github-ratelimit/github_ratelimit"

func main() {
	ctx := context.Background()
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: "Your Personal Access Token"},
	)
	tc := oauth2.NewClient(ctx, ts)
	rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient(tc.Transport)
	if err != nil {
		panic(err)
	}
	client := github.NewClient(rateLimiter)

	// now use the client as you please
}

Options

The RoundTripper accepts a set of optional options:

  • User Context: provide a context.Context to pass to callbacks.
  • Single Sleep Limit: limit the sleep time for a single rate limit.
  • Total Sleep Limit: limit the accumulated sleep time for all rate limits.

The RoundTripper accepts a set of optional callbacks:

  • On Limit Detected: callback for when a rate limit that requires sleeping is detected.
  • On Single Limit Exceeded: callback for when a rate limit that exceeds the single sleep limit is detected.
  • On Total Limit Exceeded: callback for when a rate limit that exceeds the total sleep limit is detected.

License

This package is distributed under the MIT license found in the LICENSE file.
Contribution and feedback is welcome.

About

A GoLang HTTP RoundTripper that handles GitHub API secondary rate limits

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%