A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/gofri/go-github-ratelimit below:

GitHub - gofri/go-github-ratelimit: A GoLang middleware that handles GitHub API rate limits

Package go-github-ratelimit provides a middleware (http.RoundTripper) that handles both Primary Rate Limit and Secondary Rate Limit for the GitHub API.

The module can be used with any HTTP client communicating with GitHub API. It is designed to have low overhead during good path.
It is meant to complement go-github, but there is no association between this repository and the go-github repository nor Google.

Recommended: Pagination Handling

If you like this package, please check out go-github-pagination.
It supports pagination out of the box, and plays well with the rate limit round-tripper.
It is best to stack the pagination round-tripper on top of the rate limit round-tripper.

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

see example/basic.go for a runnable example.

rateLimiter := github_ratelimit.NewClient(nil)
client := github.NewClient(rateLimiter) // .WithAuthToken("your personal access token")

// disable go-github's built-in rate limiting
ctx := context.WithValue(context.Background(), github.BypassRateLimitCheck, true)

tags, _, err := client.Repositories.ListTags(ctx, "gofri", "go-github-ratelimit", nil)
if err != nil {
  panic(err)
}

for _, tag := range tags {
  fmt.Printf("- %v\n", *tag.Name)
}

Both RoundTrippers support a set of options to configure their behavior and set callbacks.
nil callbacks are treated as no-op.

Use WithOverrideConfig(opts...) to override the configuration for a specific request (using the request context).
Per-request overrides may be useful for special cases of user requests, as well as fine-grained policy control (e.g., for a sophisticated pagination mechanism).

See example/advanced.go for a runnable example.

	rateLimiter := github_ratelimit.New(nil,
		github_primary_ratelimit.WithLimitDetectedCallback(func(ctx *github_primary_ratelimit.CallbackContext) {
			fmt.Printf("Primary rate limit detected: category %s, reset time: %v\n", ctx.Category, ctx.ResetTime)
		}),
		github_secondary_ratelimit.WithLimitDetectedCallback(func(ctx *github_secondary_ratelimit.CallbackContext) {
			fmt.Printf("Secondary rate limit detected: reset time: %v, total sleep time: %v\n", ctx.ResetTime, ctx.TotalSleepTime)
		}),
	)

	paginator := githubpagination.NewClient(rateLimiter,
		githubpagination.WithPerPage(100), // default to 100 results per page
	)
	client := github.NewClient(paginator) // .WithAuthToken("your personal access token")

	// disable go-github's built-in rate limiting
	ctx := context.WithValue(context.Background(), github.BypassRateLimitCheck, true)

	// list repository tags
	tags, _, err := client.Repositories.ListTags(ctx, "gofri", "go-github-ratelimit", nil)
	if err != nil {
		panic(err)
	}

	for _, tag := range tags {
		fmt.Printf("- %v\n", *tag.Name)
	}

The migraiton from v1 to v2 is relatively straight-forward once you check out the examples.
Please open an issue if you have any trouble -
I'd be glad to help and add documetation per need.

Github Rate Limit References

This package is distributed under the MIT license found in the LICENSE file.

Contribution and feedback is welcome.
I'm trying to drink less coffee so don't buy me one, but please do star this repository if you find it useful.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4