Documentation
¶
Index ¶
- Constants
- type Client
- func (c *Client) Delete(ctx context.Context, endpoint string, v interface{}) error
- func (c *Client) Do(ctx context.Context, method, endpoint string, body interface{}, v interface{}) error
- func (c *Client) Get(ctx context.Context, endpoint string, v interface{}) error
- func (c *Client) Post(ctx context.Context, endpoint string, body interface{}, v interface{}) error
- func (c *Client) Put(ctx context.Context, endpoint string, body interface{}, v interface{}) error
- type ClientOption
- type ErrorResponse
- func (e *ErrorResponse) Error() string
- func (e *ErrorResponse) IsBadRequest() bool
- func (e *ErrorResponse) IsForbidden() bool
- func (e *ErrorResponse) IsNotFound() bool
- func (e *ErrorResponse) IsServerError() bool
- func (e *ErrorResponse) IsTooManyRequests() bool
- func (e *ErrorResponse) IsUnauthorized() bool
- type OnRateLimitFunc
- type RateLimitTransport
Constants ¶
const ( // DefaultMaxRateLimitRetries is the default number of times to retry a // rate-limited request. DefaultMaxRateLimitRetries = 3 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an HTTP client that handles common operations for Buildkite API requests
func NewClient ¶
func NewClient(token string, opts ...ClientOption) *Client
NewClient creates a new HTTP client with the given token and options
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method, endpoint string, body interface{}, v interface{}) error
Do performs an HTTP request with the given method, endpoint, and body.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a function that modifies a Client
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL sets the base URL for API requests
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient sets the underlying HTTP client
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent sets the User-Agent header for requests
type ErrorResponse ¶
type ErrorResponse struct {
StatusCode int
Status string
URL string
Body []byte
Headers http.Header
}
ErrorResponse represents an error response from the API
func (*ErrorResponse) Error ¶
func (e *ErrorResponse) Error() string
Error implements the error interface
func (*ErrorResponse) IsBadRequest ¶ added in v3.8.0
func (e *ErrorResponse) IsBadRequest() bool
IsBadRequest returns true if the error is a 400 Bad Request
func (*ErrorResponse) IsForbidden ¶ added in v3.8.0
func (e *ErrorResponse) IsForbidden() bool
IsForbidden returns true if the error is a 403 Forbidden
func (*ErrorResponse) IsNotFound ¶ added in v3.8.0
func (e *ErrorResponse) IsNotFound() bool
IsNotFound returns true if the error is a 404 Not Found
func (*ErrorResponse) IsServerError ¶ added in v3.8.0
func (e *ErrorResponse) IsServerError() bool
IsServerError returns true if the error is a 5xx Server Error
func (*ErrorResponse) IsTooManyRequests ¶ added in v3.19.0
func (e *ErrorResponse) IsTooManyRequests() bool
IsTooManyRequests returns true if the error is a 429 Too Many Requests
func (*ErrorResponse) IsUnauthorized ¶ added in v3.8.0
func (e *ErrorResponse) IsUnauthorized() bool
IsUnauthorized returns true if the error is a 401 Unauthorized
type OnRateLimitFunc ¶ added in v3.35.0
OnRateLimitFunc is called before sleeping for a rate-limit backoff. attempt is zero-indexed; delay is how long the transport will sleep.
type RateLimitTransport ¶ added in v3.35.0
type RateLimitTransport struct {
// Transport is the underlying RoundTripper. If nil, http.DefaultTransport
// is used.
Transport http.RoundTripper
// MaxRetries is the maximum number of retry attempts on 429. Zero means
// no retries; negative values are treated as zero.
MaxRetries int
// MaxRetryDelay caps the sleep duration for any single retry. Zero means
// no cap is applied.
MaxRetryDelay time.Duration
// OnRateLimit is an optional callback invoked before each backoff sleep.
OnRateLimit OnRateLimitFunc
}
RateLimitTransport wraps an http.RoundTripper and automatically retries requests that receive an HTTP 429 response, sleeping for the duration indicated by the RateLimit-Reset header.
func NewRateLimitTransport ¶ added in v3.35.0
func NewRateLimitTransport(transport http.RoundTripper) *RateLimitTransport
NewRateLimitTransport returns a RateLimitTransport wrapping the given transport with sensible defaults.