Documentation
¶
Overview ¶
Package ghclient is the fleet's GitHub client for a command that WRITES and must not use `gh`: it authenticates from the token file only, guards the per-resource hourly budget from the rate-limit headers, spaces its writes, and backs off when GitHub answers with a secondary rate limit.
References (opened 2026-11-28):
https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api primary limit: x-ratelimit-remaining / -reset / -resource headers; secondary: at most 80 content-generating requests per minute and 500 per hour, 100 concurrent, 900 points per minute with POST/PATCH/PUT/DELETE at 5 points; on a 403 or 429 honour retry-after, else wait at least a minute.
The guard is NOT internal/fleet/budget.go: that one reads `rate_limit` through the retired `gh`. This one reads the same counter once through its own token, then learns every later value from the headers of the answers it already gets, so the guard costs no request of its own. The floor is fleet.DefaultReserve, the number the rest of the fleet stops at.
The token goes only in the Authorization header. Redirects are refused, so it never follows a Location elsewhere; https only (http for 127.0.0.1 test servers).
Index ¶
Constants ¶
const APIBase = "https://api.github.com"
APIBase is GitHub's REST and GraphQL host.
Variables ¶
var ErrReserve = errors.New("stopped at the budget reserve")
ErrReserve is what an error is when a budget has run down to its reserve.
Functions ¶
This section is empty.
Types ¶
type AccessError ¶
AccessError is a 401 or 403 that is not a rate limit: the answer is UNREAD, not empty.
func (*AccessError) Error ¶
func (e *AccessError) Error() string
type Client ¶
type Client struct {
Base string
Token string
HTTP *http.Client
Reserve int // stop when a resource has this many calls left or fewer
WriteGap time.Duration // minimum time between two writes
// SearchGap is the minimum time between two searches: the Search API allows
// 30 a minute.
SearchGap time.Duration
Backoff time.Duration // minimum wait after a secondary limit
Retries int // retries after a secondary limit
Sleep func(time.Duration)
Now func() time.Time
// contains filtered or unexported fields
}
Client is not safe for two goroutines asking at once, by design: every write here is serial.
func New ¶
New returns a client with the fleet's defaults: a reserve of reserve calls, writes at least a second apart, a minute's back-off, two retries.
func (*Client) Do ¶
Do sends one request and returns its answer whatever its status, except for a rate limit that outlasts the retries, a 401/403 that is not one, and a resource at its reserve: those are errors, never an empty answer. payload, if not nil, is sent as JSON.
type RateLimitError ¶
RateLimitError is a rate limit GitHub answered with, after the retries.
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
type ReserveError ¶
ReserveError names the resource that ran down.
func (*ReserveError) Error ¶
func (e *ReserveError) Error() string
func (*ReserveError) Is ¶
func (e *ReserveError) Is(target error) bool
Is makes errors.Is(err, ErrReserve) true.