You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Package `go-github-ratelimit`providesa middleware (http.RoundTripper) that handles both [Primary Rate Limit](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?#about-primary-rate-limits) and [Secondary Rate Limit](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?#about-secondary-rate-limits) for the GitHub API.
5
+
Package `go-github-ratelimit`provides a middleware (http.RoundTripper) that handles both [Primary Rate Limit](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?#about-primary-rate-limits) and [Secondary Rate Limit](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?#about-secondary-rate-limits) for the GitHub API.
6
6
7
7
* Primary rate limits are handled by returning a detailed error.
8
8
* Secondary rate limits are handled by waiting in blocking mode (sleep) and then issuing/retrying requests.
@@ -24,22 +24,21 @@ It is best to stack the pagination round-tripper on top of the rate limit round-
24
24
25
25
## Usage Example (with [go-github](https://github.com/google/go-github))
26
26
27
+
see [example/basic.go](example/basic.go) for a runnable example.
Both RoundTrippers support a set of options to configure their behavior and set callbacks.
49
48
nil callbacks are treated as no-op.
50
49
51
-
### Primary Rate Limit Options:
50
+
### Primary Rate Limit Options (see [options.go](github_ratelimit/github_primary_ratelimit/options.go)):
52
51
53
52
-`WithLimitDetectedCallback(callback)`: the callback is triggered when any primary rate limit is detected.
54
53
-`WithRequestPreventedCallback(callback)`: the callback is triggered when a request is prevented due to an active rate limit.
@@ -57,7 +56,7 @@ nil callbacks are treated as no-op.
57
56
-`WithSharedState(state)`: share state between multiple clients (e.g., for a single user running concurrently).
58
57
-`WithBypassLimit()`: bypass the rate limit mechanism, i.e., do not prevent requests when a rate limit is active.
59
58
60
-
### Secondary Rate Limit Options:
59
+
### Secondary Rate Limit Options (see [options.go](github_ratelimit/github_secondary_ratelimit/options.go)):
61
60
62
61
-`WithLimitDetectedCallback(callback)`: the callback is triggered before a sleep.
63
62
-`WithSingleSleepLimit(duration, callback)`: limit the sleep duration for a single secondary rate limit & trigger a callback when the limit is exceeded.
@@ -72,18 +71,8 @@ as well as fine-grained policy control (e.g., for a sophisticated pagination mec
72
71
73
72
## Advanced Example
74
73
74
+
See [example/advanced.go](example/advanced.go) for a runnable example.
0 commit comments