Documentation
¶
Index ¶
- Variables
- type CircuitBreaker
- type CircuitState
- type Client
- func (c *Client) Delete(ctx context.Context, path string) error
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) Get(ctx context.Context, path string, result interface{}) error
- func (c *Client) Post(ctx context.Context, path string, body, result interface{}) error
- func (c *Client) Put(ctx context.Context, path string, body, result interface{}) error
- type Option
- func WithBaseURL(url string) Option
- func WithCircuitBreaker() Option
- func WithCircuitBreakerConfig(maxFailures int, timeout, resetTimeout time.Duration) Option
- func WithHTTPClient(httpClient *http.Client) Option
- func WithHeader(key, value string) Option
- func WithHeaders(headers map[string]string) Option
- func WithRetry(maxRetries int, delay time.Duration) Option
- func WithRetryableStatuses(statuses []int) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTransport(transport http.RoundTripper) Option
- type RetryConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCircuitOpen is returned when the circuit breaker is open ErrCircuitOpen = errors.New("circuit breaker is open") )
Functions ¶
This section is empty.
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker implements the circuit breaker pattern
func NewCircuitBreaker ¶
func NewCircuitBreaker(maxFailures int, timeout, resetTimeout time.Duration) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker maxFailures: number of consecutive failures before opening the circuit timeout: how long to wait before attempting recovery (half-open state) resetTimeout: how long to keep the circuit open before moving to half-open
func (*CircuitBreaker) GetFailures ¶
func (cb *CircuitBreaker) GetFailures() int
GetFailures returns the current number of failures
func (*CircuitBreaker) GetState ¶
func (cb *CircuitBreaker) GetState() CircuitState
GetState returns the current state of the circuit breaker
func (*CircuitBreaker) Reset ¶
func (cb *CircuitBreaker) Reset()
Reset manually resets the circuit breaker to closed state
type CircuitState ¶
type CircuitState int
CircuitState represents the state of the circuit breaker
const ( // StateClosed means the circuit is closed and requests are allowed StateClosed CircuitState = iota // StateOpen means the circuit is open and requests are blocked StateOpen // StateHalfOpen means the circuit is testing if the service has recovered StateHalfOpen )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a standardized HTTP client with retry and circuit breaker support
type Option ¶
type Option func(*Client)
Option is a function that configures the Client
func WithBaseURL ¶
WithBaseURL sets the base URL for all requests
func WithCircuitBreaker ¶
func WithCircuitBreaker() Option
WithCircuitBreaker enables circuit breaker with default settings
func WithCircuitBreakerConfig ¶
WithCircuitBreakerConfig enables circuit breaker with custom settings
func WithHTTPClient ¶
WithHTTPClient allows using a custom HTTP client
func WithHeader ¶
WithHeader adds a default header to all requests
func WithHeaders ¶
WithHeaders adds multiple default headers to all requests
func WithRetryableStatuses ¶
WithRetryableStatuses sets which HTTP status codes should trigger a retry
func WithTimeout ¶
WithTimeout sets the HTTP client timeout
func WithTransport ¶
func WithTransport(transport http.RoundTripper) Option
WithTransport sets a custom HTTP transport