Documentation
¶
Index ¶
- Variables
- type APIError
- type ErrorItem
- type ForbiddenError
- type HTTPAPI
- func (g *HTTPAPI) DeleteJSON(ctx context.Context, uri string, post interface{}, dest interface{}, ...) (interface{}, error)
- func (g *HTTPAPI) GetJSON(ctx context.Context, uri string, dest interface{}, options ...ReqOptions) (interface{}, error)
- func (g *HTTPAPI) PostJSON(ctx context.Context, uri string, post interface{}, dest interface{}, ...) (interface{}, error)
- func (g *HTTPAPI) PutJSON(ctx context.Context, uri string, post interface{}, dest interface{}, ...) (interface{}, error)
- func (g *HTTPAPI) ReqJSON(ctx context.Context, method string, uri string, post interface{}, ...) (interface{}, error)
- func (g *HTTPAPI) ResolveBase(base *url.URL, uri string) string
- type RateInfo
- type RateLimiter
- type ReqOptions
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type ForbiddenError ¶ added in v1.2.0
type HTTPAPI ¶
HTTPAPI represents an HTTP API client
func NewHTTPAPI ¶
NewHTTPAPI creates a new API client with default rate limit of 100 reqs/min
func (*HTTPAPI) DeleteJSON ¶
type RateInfo ¶
type RateInfo struct {
Limit int // x-ratelimit-limit
Remaining int // x-ratelimit-remaining
Used int // x-ratelimit-used
Reset int64 // x-ratelimit-reset
RetryAfter int64 // x-ratelimit-retry-after
Resource string // x-ratelimit-resource
}
RateInfo contains information about API rate limits
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter wraps the golang.org/x/time/rate Limiter
func NewRateLimiter ¶
func NewRateLimiter(requestsPerMinute int) *RateLimiter
NewRateLimiter creates a new rate limiter with default values
func (*RateLimiter) Allow ¶
func (r *RateLimiter) Allow() bool
Allow checks if a request is allowed based on rate limits and consumes a token if available
func (*RateLimiter) IsAllowed ¶
func (r *RateLimiter) IsAllowed() (bool, time.Duration)
IsAllowed checks if a request is allowed based on rate limits without blocking Returns true if allowed, false if rate limited, and duration to wait if limited
func (*RateLimiter) RemainingTokens ¶
func (r *RateLimiter) RemainingTokens() float64
RemainingTokens returns an estimate of the number of remaining requests
func (*RateLimiter) Wait ¶
func (r *RateLimiter) Wait(ctx context.Context) error
Wait blocks until a request can be allowed or the context is done
func (*RateLimiter) WaitMaxDuration ¶
WaitMaxDuration tries to wait for a token but only up to the specified max duration