Documentation
¶
Index ¶
- Constants
- Variables
- func AbuseRetryAfter(err error) time.Duration
- func CheckRateLimit(ctx context.Context, resp *github.Response) error
- func CheckTokenQuota(token string) int
- func Deref(s *string) string
- func GetGitHubDeveloper(ctx context.Context, client *http.Client, username string) (*data.Developer, error)
- func GetLabels(labels []*github.Label) []string
- func GetUsernames(users ...*github.User) []string
- func HasSufficientQuota(token string) bool
- func IsRateLimited(err error) bool
- func MapUserToDeveloper(u *github.User) *data.Developer
- func MinTokenQuota() int
- func ParseDate(t *time.Time) string
- func ParseUsers(body *string) []string
- func RateInfo(r *github.Rate) string
- func Trim(s *string) string
- func WaitForRateReset(ctx context.Context, err error) bool
- type TokenPool
Constants ¶
const RateLimitThreshold = 10
Variables ¶
var ErrRateLimited = errors.New("github token rate limited")
ErrRateLimited is returned when a GitHub API token has hit its rate limit. Callers with a token pool should exhaust this token and try another.
Functions ¶
func AbuseRetryAfter ¶
AbuseRetryAfter returns the retry-after duration if the error is a secondary (abuse) rate limit error. Returns 0 if the error is not an abuse rate limit.
func CheckTokenQuota ¶ added in v0.30.3
CheckTokenQuota calls the GitHub rate_limit API (free, no quota cost) and returns the remaining quota. Returns -1 on error (treat as usable).
func GetGitHubDeveloper ¶
func GetUsernames ¶
func HasSufficientQuota ¶ added in v0.30.3
HasSufficientQuota returns true if the token has enough remaining API calls.
func IsRateLimited ¶ added in v0.28.0
IsRateLimited reports whether err (or any error in its chain) indicates a GitHub rate limit has been reached. Matches ErrRateLimited, github.RateLimitError, and github.AbuseRateLimitError.
func MinTokenQuota ¶ added in v0.30.3
func MinTokenQuota() int
MinTokenQuota returns the minimum remaining API calls required for a token to be included in the pool.
func ParseUsers ¶
func WaitForRateReset ¶ added in v0.17.6
WaitForRateReset checks whether err is a GitHub primary or secondary rate limit error. If so it sleeps until the reset time (plus jitter) and returns true so the caller can retry. Returns false for non-rate-limit errors or if the wait would exceed maxWait.
Types ¶
type TokenPool ¶
type TokenPool struct {
// contains filtered or unexported fields
}
TokenPool manages a pool of GitHub API tokens using round-robin selection. Safe for concurrent use. Works transparently with a single token. Tracks per-token usage counts for observability and supports marking individual tokens as exhausted (e.g. after hitting a rate limit).
func NewTokenPool ¶
NewTokenPool creates a pool from one or more tokens. Tokens can be passed individually or as a single comma-separated string.
func (*TokenPool) ActiveCount ¶ added in v0.28.0
ActiveCount returns the number of non-exhausted tokens.
func (*TokenPool) Exhaust ¶ added in v0.28.0
Exhaust marks the given token as exhausted so Token() skips it.
func (*TokenPool) Token ¶
Token returns the next non-exhausted token in the round-robin rotation. Returns "" when all tokens are exhausted or the pool is empty.
func (*TokenPool) UsageCounts ¶ added in v0.18.0
UsageCounts returns a copy of per-token call counts (indexed by pool position).