Documentation
¶
Overview ¶
Package ratelimit is a thin facade over github.com/gofri/go-github-ratelimit/v2.
It wires the primary + secondary rate limiters with sensible defaults (sanitised slog logging, 1 hour secondary sleep cap) and exposes the upstream CallbackContext types directly as type aliases so advanced callers can use them without importing the upstream package. The wrapper adds no behaviour beyond the defaults; import the upstream directly if you need full control.
Index ¶
- func NewTransport(base http.RoundTripper, opts ...Option) http.RoundTripper
- type Option
- func WithLogger(l *slog.Logger) Option
- func WithPrimaryLimitDetected(cb func(*PrimaryEvent)) Option
- func WithPrimaryLimitReset(cb func(*PrimaryEvent)) Option
- func WithSecondaryLimitDetected(cb func(*SecondaryEvent)) Option
- func WithTotalSleepLimit(d time.Duration) Option
- func WithUpstreamOptions(opts ...any) Option
- type PrimaryEvent
- type SecondaryEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTransport ¶
func NewTransport(base http.RoundTripper, opts ...Option) http.RoundTripper
NewTransport wraps base with primary + secondary GitHub rate limiting. When callbacks are not supplied, default handlers log sanitised events:
- primary detected: logger.Error "ratelimit_primary_detected" kind=primary limit_type=<category>
- primary reset: logger.Info "ratelimit_primary_reset" kind=primary limit_type=<category>
- secondary detected: logger.Error "ratelimit_secondary_detected" kind=secondary sleep_duration=<d>
The raw CallbackContext is never logged; we read only safe scalar fields.
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures a Transport.
func WithLogger ¶
WithLogger supplies the slog.Logger for default event logging. Default: slog.Default().
func WithPrimaryLimitDetected ¶
func WithPrimaryLimitDetected(cb func(*PrimaryEvent)) Option
WithPrimaryLimitDetected registers a callback that fires when the primary rate limit is reached.
func WithPrimaryLimitReset ¶
func WithPrimaryLimitReset(cb func(*PrimaryEvent)) Option
WithPrimaryLimitReset registers a callback that fires when the primary rate limit resets.
func WithSecondaryLimitDetected ¶
func WithSecondaryLimitDetected(cb func(*SecondaryEvent)) Option
WithSecondaryLimitDetected registers a callback that fires when the secondary rate limit is detected.
func WithTotalSleepLimit ¶
WithTotalSleepLimit caps the cumulative sleep the secondary limiter will incur. Default: 1 hour.
func WithUpstreamOptions ¶
WithUpstreamOptions appends raw upstream options from github.com/gofri/go-github-ratelimit/v2 to the constructed transport. Use this for upstream features ghkit does not expose as named options (the secondary abort callback, custom limit providers, before-request hooks). Applied after ghkit's named options, so they can override callbacks ghkit installed by default.
type PrimaryEvent ¶
type PrimaryEvent = github_primary_ratelimit.CallbackContext
PrimaryEvent is an alias for the upstream primary rate-limit callback context. Exposed so callers can type callbacks without importing the upstream package.
type SecondaryEvent ¶
type SecondaryEvent = github_secondary_ratelimit.CallbackContext
SecondaryEvent is an alias for the upstream secondary rate-limit callback context.