This commit is contained in:
+18
-2
@@ -25,8 +25,18 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO: Implement client retry configuration
|
||||
// Also support exponential backoff
|
||||
// RetryConfig controls how transient request failures (transport errors and 5xx
|
||||
// responses) are retried. The zero value disables retries.
|
||||
type RetryConfig struct {
|
||||
// MaxRetries is the number of additional attempts made after the initial
|
||||
// request. Zero means no retries.
|
||||
MaxRetries int
|
||||
// BaseDelay is the wait before the first retry. It doubles on each
|
||||
// subsequent retry (exponential backoff). Zero means retry immediately.
|
||||
BaseDelay time.Duration
|
||||
// MaxDelay caps the per-retry backoff delay. Zero means no cap.
|
||||
MaxDelay time.Duration
|
||||
}
|
||||
|
||||
// Default ports exposed by an MGW310 station.
|
||||
const (
|
||||
@@ -92,6 +102,7 @@ type Client struct {
|
||||
tar1090 *Endpoint
|
||||
http *http.Client
|
||||
userAgent string
|
||||
retry RetryConfig
|
||||
}
|
||||
|
||||
// Option customizes a Client.
|
||||
@@ -125,6 +136,11 @@ func WithUserAgent(ua string) Option {
|
||||
return func(c *Client) { c.userAgent = ua }
|
||||
}
|
||||
|
||||
// WithRetry enables retries with exponential backoff for transient failures.
|
||||
func WithRetry(cfg RetryConfig) Option {
|
||||
return func(c *Client) { c.retry = cfg }
|
||||
}
|
||||
|
||||
// New constructs a Client from options. A Wingbits endpoint with a non-empty
|
||||
// Host must be supplied via WithWingbitsEndpoint.
|
||||
func New(opts ...Option) (*Client, error) {
|
||||
|
||||
Reference in New Issue
Block a user