ratelimit

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 7 Imported by: 0

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

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

func WithLogger(l *slog.Logger) Option

WithLogger supplies the slog.Logger for default event logging. Pass nil (or omit the option) to silence the default callbacks; a nil logger is replaced with slog.New(slog.DiscardHandler) at construction.

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

func WithTotalSleepLimit(d time.Duration) Option

WithTotalSleepLimit caps the cumulative sleep the secondary limiter will incur. Default: 1 hour.

func WithUpstreamOptions

func WithUpstreamOptions(opts ...any) Option

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-mismatched values are silently dropped by the upstream constructor; verify the upstream package's option types when forwarding.

type PrimaryEvent

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

SecondaryEvent is an alias for the upstream secondary rate-limit callback context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL