Documentation ¶
Overview ¶
Package relax provides HTTP client and server implementations that provide rate limitation and caching.
Index ¶
- type Client
- type ClientFeature
- func WithCache(defaultExpiration, cleanupInterval time.Duration) ClientFeature
- func WithDefaultCache() ClientFeature
- func WithDefaultLimiter() ClientFeature
- func WithDefaultTimeout(duration time.Duration) ClientFeature
- func WithLimiter(limit float64, burst int) ClientFeature
- func WithTimeout(duration time.Duration) ClientFeature
- type ClientOption
- type Modifier
- type Modifiers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Cache *cache.Cache Credentials *clientcredentials.Config HTTP *http.Client Limiter *rate.Limiter Timeout time.Duration }
Client represents an HTTP client with additional possible features
func New ¶
func New(option ClientOption, feats ...ClientFeature) *Client
New creates a new client with a specified option along with the optional features implemented.
type ClientFeature ¶
type ClientFeature func(c *Client)
ClientFeature is a functional option for a client to specify additional optional features on top of the default implementation
func WithCache ¶
func WithCache(defaultExpiration, cleanupInterval time.Duration) ClientFeature
WithCache allows the client to utilize a cache with a specified expiration time and cleanup interval
func WithDefaultCache ¶
func WithDefaultCache() ClientFeature
WithDefaultCache allows the client to utilize a cache with default values
func WithDefaultLimiter ¶
func WithDefaultLimiter() ClientFeature
WithDefaultLimiter allows the client to use a rate limiter for requests using default values
func WithDefaultTimeout ¶
func WithDefaultTimeout(duration time.Duration) ClientFeature
WithDefaultTimeout allows the client to timeout after a default duration of 5 seconds
func WithLimiter ¶
func WithLimiter(limit float64, burst int) ClientFeature
WithLimiter allows the client to use a rate limiter for requests
func WithTimeout ¶
func WithTimeout(duration time.Duration) ClientFeature
WithTimeout allows the client to timeout after a specified duration
type ClientOption ¶
type ClientOption func(c *Client)
ClientOption specifies how to create a client
func FromClient ¶
func FromClient(http *http.Client) ClientOption
FromClient creates a client from a specified HTTP client
func FromConfig ¶
func FromConfig(cred *clientcredentials.Config) ClientOption
FromConfig creates a client from a specified OAuth client configuration
func FromCredentials ¶
func FromCredentials(apiKey, apiKeySecret, tokenURL string) ClientOption
FromCredentials creates a client from OAuth credentials
func FromDefaultClient ¶
func FromDefaultClient() ClientOption
FromDefaultClient creates a client from the default HTTP implementation
type Modifier ¶
type Modifier func(m *Modifiers)
Modifier is a functional option for a request
func UseCache ¶
UseCache forces the client to attempt to pull from a cache, if the request was already made, or otherwise update the cache.
func UseLimiter ¶
UseLimiter forces the client to obey rate limiting rules when performing the request or not.