httpclient

package module
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 23 Imported by: 0

README

go-httpclient

Go Version License Go Report Card GoDoc

A production-ready HTTP client for Go with built-in resilience patterns (retry, circuit breaker, timeouts, fallback, and more). It’s designed for reliable microservices and external API integrations.

Features

Resilience patterns (built-in)
  • Retry policy: max attempts/retries, max duration, fixed delay, exponential backoff, random delay, jitter
  • Circuit breaker: count- or ratio-based thresholds with open/half-open/close hooks
  • Timeout: per-execution timeout policy (in addition to context.Context)
  • Fallback: custom fallback response when failures happen
  • Rate limiter: smooth or bursty limiting
  • Bulkhead: limit concurrent executions and queue wait time
  • Hedging: tail-latency hedging with optional cancellation on first good result
  • Adaptive throttling: automatically reject requests when failure rate is high
  • Cache (read-through): cache *http.Response via failsafe-go cache policy
Developer experience
  • Simple API (Get, Post, Do, plus *JSON helpers)
  • Built-in JSON marshaling/unmarshaling
  • context.Context support for cancellation and deadlines
  • Typed errors with rich context + pluggable error body parsers

Installation

go get github.com/ja7ad/httpclient

Quick start

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/ja7ad/httpclient"
)

type User struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

func main() {
	// NewDefaultClient sets JSON headers and enables a production-ready resilience config.
	client := httpclient.NewDefaultClient("https://jsonplaceholder.typicode.com")

	var user User
	if err := client.GetJSON(context.Background(), "/users/1", &user); err != nil {
		log.Fatalf("request failed: %v", err)
	}

	fmt.Printf("User: %+v\n", user)
}

Client configuration

Constructors
  • NewDefaultClient(baseURL)
    • sets Content-Type: application/json and Accept: application/json
    • enables DefaultResilienceConfig()
  • NewClient(...ClientOption)
    • fully configurable via options
Options

Available ClientOptions:

  • WithBaseURL(baseURL string)
  • WithTimeout(timeout time.Duration) (applied to http.Client.Timeout when it’s 0)
  • WithHeader(key, value string) / WithHeaders(map[string]string)
  • WithResilienceConfig(cfg *ResilienceConfig) (wraps the transport with resilience policies)
  • WithHTTPClient(httpClient *http.Client)
  • WithErrorParser(parser ErrorResponseParser) (adds a parser to the error parsing chain)

Make Client Faster

We use encoding/json as default json library due to stability and producibility. However, the standard library is a bit slow compared to 3rd party libraries. If you're not happy with the performance of encoding/json, we recommend you to use these libraries:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/ja7ad/httpclient"
	"github.com/bytedance/sonic"
)

type User struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

func main() {
	// NewDefaultClient sets JSON headers and enables a production-ready resilience config.
	client := httpclient.NewClient(
		httpclient.WithBaseURL("https://jsonplaceholder.typicode.com"),
	    httpclient.WithCustomJsonMarshaler(sonic.Marshal),
        httpclient.WithCustomJsonUnmarshaler(sonic.Unmarshal),
	)

	var user User
	if err := client.GetJSON(context.Background(), "/users/1", &user); err != nil {
		log.Fatalf("request failed: %v", err)
	}

	fmt.Printf("User: %+v\n", user)
}

Resilience

How policies are applied

Policies wrap a base http.RoundTripper in this order (innermost → outermost):

Fallback → Cache → Retry → Hedge → CircuitBreaker → RateLimiter → AdaptiveThrottler → Bulkhead → Timeout

Using ResilienceConfig
package main

import (
	"context"
	"fmt"
	"log"
	"net/http"
	"time"

	"github.com/failsafe-go/failsafe-go"
	"github.com/failsafe-go/failsafe-go/circuitbreaker"
	"github.com/ja7ad/httpclient"
)

func main() {
	cfg := &httpclient.ResilienceConfig{
		RetryPolicy: &httpclient.RetryPolicyConfig{
			Enabled:        true,
			MaxAttempts:    5,
			BackoffInitial: 100 * time.Millisecond,
			BackoffMax:     3 * time.Second,
			JitterFactor:   0.2,
			RetryableStatus: []int{
				http.StatusInternalServerError,
				http.StatusBadGateway,
				http.StatusServiceUnavailable,
				http.StatusGatewayTimeout,
				http.StatusTooManyRequests,
			},
			OnRetry: func(event failsafe.ExecutionEvent[*http.Response]) {
				fmt.Printf("retry attempt: %d\n", event.Attempts())
			},
		},
		CircuitBreaker: &httpclient.CircuitBreakerConfig{
			Enabled:          true,
			FailureThreshold: 3,
			SuccessThreshold: 2,
			Delay:            5 * time.Second,
			OnOpen: func(event circuitbreaker.StateChangedEvent) {
				fmt.Println("circuit opened")
			},
			OnHalfOpen: func(event circuitbreaker.StateChangedEvent) {
				fmt.Println("circuit half-open")
			},
			OnClose: func(event circuitbreaker.StateChangedEvent) {
				fmt.Println("circuit closed")
			},
		},
		Timeout: &httpclient.TimeoutConfig{
			Enabled:  true,
			Duration: 10 * time.Second,
		},
		RateLimiter: &httpclient.RateLimiterConfig{
			Enabled:       true,
			MaxExecutions: 50,
			Period:        time.Second,
			IsBursty:      false,
		},
		Bulkhead: &httpclient.BulkheadConfig{
			Enabled:        true,
			MaxConcurrency: 10,
			MaxWaitTime:    200 * time.Millisecond,
		},
	}

	client := httpclient.NewClient(
		httpclient.WithBaseURL("https://httpstat.us"),
		httpclient.WithResilienceConfig(cfg),
	)

	resp, err := client.Get(context.Background(), "/200")
	if err != nil {
		log.Fatalf("request failed: %v", err)
	}
	defer resp.Body.Close()

	fmt.Println("status:", resp.StatusCode)
}
Using ResilienceBuilder (fluent)
package main

import (
	"time"

	"github.com/ja7ad/httpclient"
)

func main() {
	cfg := httpclient.NewResilienceBuilder().
		WithRetryPolicy(&httpclient.RetryPolicyConfig{
			Enabled:        true,
			MaxAttempts:    3,
			BackoffInitial: 100 * time.Millisecond,
			BackoffMax:     2 * time.Second,
			JitterFactor:   0.1,
		}).
		WithCircuitBreaker(&httpclient.CircuitBreakerConfig{
			Enabled:          true,
			FailureThreshold: 5,
			SuccessThreshold: 2,
			Delay:            10 * time.Second,
		}).
		WithRateLimiter(&httpclient.RateLimiterConfig{
			Enabled:       true,
			MaxExecutions: 100,
			Period:        time.Second,
			IsBursty:      true,
		}).
		WithBulkhead(&httpclient.BulkheadConfig{
			Enabled:        true,
			MaxConcurrency: 20,
			MaxWaitTime:    time.Second,
		}).
		Build()

	_ = cfg
}
Fallback example
package main

import (
	"context"
	"io"
	"log"
	"net/http"
	"strings"

	"github.com/failsafe-go/failsafe-go"
	"github.com/ja7ad/httpclient"
)

func main() {
	cfg := &httpclient.ResilienceConfig{
		Fallback: &httpclient.FallbackConfig{
			Enabled: true,
			FallbackFunc: func(exec failsafe.Execution[*http.Response]) (*http.Response, error) {
				// Return a synthetic response when the primary request fails.
				body := `{"id": 1, "name": "Cached User"}`
				return &http.Response{
					StatusCode: http.StatusOK,
					Header:     http.Header{"Content-Type": []string{"application/json"}},
					Body:       io.NopCloser(strings.NewReader(body)),
				}, nil
			},
		},
	}

	client := httpclient.NewClient(
		httpclient.WithBaseURL("https://invalid-domain-that-does-not-exist.com"),
		httpclient.WithResilienceConfig(cfg),
	)

	resp, err := client.Get(context.Background(), "/users/1")
	if err != nil {
		log.Fatalf("request failed: %v", err)
	}
	defer resp.Body.Close()

	log.Println("status:", resp.StatusCode)
}

Errors

All errors returned by this package are standard Go errors. For richer information, use errors.As to unwrap *httpclient.Error.

Typed error fields

*httpclient.Error includes:

  • Type (timeout, network, http, retry_exhausted, validation, unknown)
  • StatusCode (for HTTP errors)
  • URL, Method
  • RequestID (from X-Request-ID, if present)
  • CorrelationID, ErrorCode, Details (parsed from the error response body when possible)
Custom error response parsing

By default, the client parses common API error formats using an ErrorParserChain:

  1. Sumsub
  2. Stripe
  3. RFC 7807 (Problem Details)
  4. Generic JSON parser (always last)

You can add your own parser with WithErrorParser(...):

package main

import (
	"context"
	"errors"
	"fmt"
	"log"

	"github.com/ja7ad/httpclient"
)

func main() {
	client := httpclient.NewDefaultClient("https://api.sumsub.com")
	client.SetHeader("Authorization", "Bearer your-token")

	var result map[string]any
	err := client.GetJSON(context.Background(), "/resources/applicants/12313213", &result)
	if err == nil {
		return
	}

	var httpErr *httpclient.Error
	if errors.As(err, &httpErr) {
		fmt.Printf("type: %s\n", httpErr.Type)
		fmt.Printf("message: %s\n", httpErr.Message)
		fmt.Printf("status: %d\n", httpErr.StatusCode)
		fmt.Printf("errorCode: %s\n", httpErr.ErrorCode)
		fmt.Printf("correlationID: %s\n", httpErr.CorrelationID)
		if v, ok := httpErr.GetDetail("description"); ok {
			fmt.Printf("description: %v\n", v)
		}
		return
	}

	log.Printf("request failed: %v", err)
}

License

MIT. See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResilientClient

func NewResilientClient(cfg *ResilienceConfig) *http.Client

NewResilientClient creates an HTTP client with resilience policies This is the recommended way to create a resilient HTTP client

func NewResilientTransport

func NewResilientTransport(baseTransport http.RoundTripper, cfg *ResilienceConfig) http.RoundTripper

NewResilientTransport wraps an existing transport with resilience policies Use this if you need to customize the base transport

Types

type AdaptiveThrottlerConfig added in v1.3.0

type AdaptiveThrottlerConfig struct {
	Enabled              bool
	FailureRateThreshold float64
	MinExecutions        uint
	Period               time.Duration
	MaxRejectionRate     float64
}

AdaptiveThrottlerConfig limits requests based on failure rate

type BulkheadConfig added in v1.3.0

type BulkheadConfig struct {
	Enabled        bool
	MaxConcurrency uint
	MaxWaitTime    time.Duration
}

BulkheadConfig limits concurrent executions to prevent resource exhaustion

type CacheConfig added in v1.3.0

type CacheConfig struct {
	Enabled bool
	Cache   cachepolicy.Cache[*http.Response]
	Key     string
}

CacheConfig provides read-through caching

type CircuitBreakerConfig

type CircuitBreakerConfig struct {
	Enabled               bool
	FailureThreshold      uint            // Count-based: Opens after N consecutive failures
	FailureThresholdRatio *ThresholdRatio // Ratio-based: Opens when X of Y executions fail
	SuccessThreshold      uint            // Count-based: Closes after N consecutive successes in half-open
	SuccessThresholdRatio *ThresholdRatio // Ratio-based: Closes when X of Y executions succeed in half-open
	Delay                 time.Duration   // Time to wait in open state before half-opening
	OnStateChanged        func(event circuitbreaker.StateChangedEvent)
	OnOpen                func(event circuitbreaker.StateChangedEvent)
	OnHalfOpen            func(event circuitbreaker.StateChangedEvent)
	OnClose               func(event circuitbreaker.StateChangedEvent)
}

CircuitBreakerConfig holds circuit breaker configuration

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...ClientOption) *Client

func NewDefaultClient

func NewDefaultClient(baseURL string) *Client

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) (*http.Response, error)

func (*Client) DeleteJSON

func (c *Client) DeleteJSON(ctx context.Context, path string, result any) error

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body any) (*http.Response, error)

func (*Client) DoWithResponse

func (c *Client) DoWithResponse(ctx context.Context, method, path string, body, result any) error

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)

func (*Client) GetErrorParser added in v1.1.0

func (c *Client) GetErrorParser() *ErrorParserChain

func (*Client) GetHTTPClient

func (c *Client) GetHTTPClient() *http.Client

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, path string, result any) error

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, path string, body any) (*http.Response, error)

func (*Client) PatchJSON

func (c *Client) PatchJSON(ctx context.Context, path string, body, result any) error

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body any) (*http.Response, error)

func (*Client) PostJSON

func (c *Client) PostJSON(ctx context.Context, path string, body, result any) error

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body any) (*http.Response, error)

func (*Client) PutJSON

func (c *Client) PutJSON(ctx context.Context, path string, body, result any) error

func (*Client) RemoveHeader

func (c *Client) RemoveHeader(key string)

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(baseURL string)

func (*Client) SetErrorParser added in v1.1.0

func (c *Client) SetErrorParser(parser *ErrorParserChain)

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(httpClient *http.Client)

func (*Client) SetHeader

func (c *Client) SetHeader(key, value string)

func (*Client) SetHeaders

func (c *Client) SetHeaders(headers map[string]string)

type ClientOption

type ClientOption func(*Client)

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

func WithCustomJsonMarshaler added in v1.3.1

func WithCustomJsonMarshaler(marshal JSONMarshal) ClientOption

WithCustomJsonMarshaler set custom marshal from external packages instead encoding/json. we use encoding/json as default json library due to stability and producibility. However, the standard library is a bit slow compared to 3rd party libraries. If you're not happy with the performance of encoding/json.

supported package: goccy/go-json, bytedance/sonic, segmentio/encoding, minio/simdjson-go, wI2L/jettison, mailru/easyjson.

default is encoding/json

func WithCustomJsonUnmarshaler added in v1.3.1

func WithCustomJsonUnmarshaler(unmarshal JSONUnmarshal) ClientOption

WithCustomJsonUnmarshaler set custom unmarshal from external packages instead encoding/json. we use encoding/json as default json library due to stability and producibility. However, the standard library is a bit slow compared to 3rd party libraries. If you're not happy with the performance of encoding/json.

supported package: goccy/go-json, bytedance/sonic, segmentio/encoding, minio/simdjson-go, wI2L/jettison, mailru/easyjson.

default is encoding/json

func WithErrorParser added in v1.1.0

func WithErrorParser(parser ErrorResponseParser) ClientOption

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

func WithHeader

func WithHeader(key, value string) ClientOption

func WithHeaders

func WithHeaders(headers map[string]string) ClientOption

func WithResilienceConfig

func WithResilienceConfig(cfg *ResilienceConfig) ClientOption

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

type Error

type Error struct {
	Type          ErrorType              `json:"type"`
	Message       string                 `json:"message"`
	StatusCode    int                    `json:"status_code,omitempty"`
	URL           string                 `json:"url"`
	Method        string                 `json:"method"`
	RequestID     string                 `json:"request_id,omitempty"`
	CorrelationID string                 `json:"correlation_id,omitempty"`
	ErrorCode     string                 `json:"error_code,omitempty"`
	Details       map[string]interface{} `json:"details,omitempty"`
	Err           error                  `json:"-"`
	Timestamp     time.Time              `json:"timestamp"`
	ResponseBody  []byte                 `json:"-"`
}

Error represents an HTTP client error with detailed context

func (*Error) Error

func (e *Error) Error() string

func (*Error) GetDetail added in v1.1.0

func (e *Error) GetDetail(key string) (interface{}, bool)

GetDetail retrieves a specific detail from the error response

func (*Error) HasDetail added in v1.1.0

func (e *Error) HasDetail(key string) bool

HasDetail checks if a specific detail key exists

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorParserChain added in v1.1.0

type ErrorParserChain struct {
	// contains filtered or unexported fields
}

ErrorParserChain tries multiple parsers in order

func NewErrorParserChain added in v1.1.0

func NewErrorParserChain() *ErrorParserChain

func (*ErrorParserChain) AddParser added in v1.1.0

func (c *ErrorParserChain) AddParser(parser ErrorResponseParser)

func (*ErrorParserChain) Parse added in v1.1.0

func (c *ErrorParserChain) Parse(body []byte) (*ParsedErrorResponse, error)

type ErrorResponseParser added in v1.1.0

type ErrorResponseParser interface {
	Parse(body []byte) (*ParsedErrorResponse, error)
	CanParse(body []byte) bool
}

ErrorResponseParser defines an interface for parsing custom error responses

type ErrorType

type ErrorType string
const (
	ErrorTypeTimeout        ErrorType = "timeout"
	ErrorTypeNetwork        ErrorType = "network"
	ErrorTypeHTTP           ErrorType = "http"
	ErrorTypeRetryExhausted ErrorType = "retry_exhausted"
	ErrorTypeValidation     ErrorType = "validation"
	ErrorTypeUnknown        ErrorType = "unknown"
)

type Executor added in v1.1.2

type Executor interface {
	Get(ctx context.Context, path string) (*http.Response, error)
	Post(ctx context.Context, path string, body any) (*http.Response, error)
	Put(ctx context.Context, path string, body any) (*http.Response, error)
	Patch(ctx context.Context, path string, body any) (*http.Response, error)
	Delete(ctx context.Context, path string) (*http.Response, error)
	Do(ctx context.Context, method, path string, body any) (*http.Response, error)
	DoWithResponse(ctx context.Context, method, path string, body, result any) error
	GetJSON(ctx context.Context, path string, result any) error
	PostJSON(ctx context.Context, path string, body, result any) error
	PutJSON(ctx context.Context, path string, body, result any) error
	PatchJSON(ctx context.Context, path string, body, result any) error
	DeleteJSON(ctx context.Context, path string, result any) error
	GetErrorParser() *ErrorParserChain
	SetErrorParser(parser *ErrorParserChain)
	SetBaseURL(baseURL string)
	SetHeader(key, value string)
	SetHeaders(headers map[string]string)
	RemoveHeader(key string)
	GetHTTPClient() *http.Client
	SetHTTPClient(httpClient *http.Client)
}

type FallbackConfig

type FallbackConfig struct {
	Enabled            bool
	FallbackFunc       func(exec failsafe.Execution[*http.Response]) (*http.Response, error)
	OnFallbackExecuted func(event failsafe.ExecutionDoneEvent[*http.Response])
}

FallbackConfig holds fallback configuration

type GenericErrorParser added in v1.1.0

type GenericErrorParser struct{}

GenericErrorParser parses common error response formats

func (*GenericErrorParser) CanParse added in v1.1.0

func (p *GenericErrorParser) CanParse(body []byte) bool

func (*GenericErrorParser) Parse added in v1.1.0

func (p *GenericErrorParser) Parse(body []byte) (*ParsedErrorResponse, error)

type HedgeConfig added in v1.3.0

type HedgeConfig struct {
	Enabled        bool
	Delay          time.Duration
	MaxHedges      int
	CancelOnResult bool // Cancel outstanding hedges once a result is received
}

HedgeConfig handles tail latency by sending backup requests

type JSONMarshal added in v1.3.1

type JSONMarshal func(v interface{}) ([]byte, error)

JSONMarshal returns the JSON encoding of v.

type JSONUnmarshal added in v1.3.1

type JSONUnmarshal func(data []byte, v interface{}) error

JSONUnmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.

type MockErrorResponseParser added in v1.1.3

type MockErrorResponseParser struct {
	mock.Mock
}

MockErrorResponseParser is an autogenerated mock type for the ErrorResponseParser type

func NewMockErrorResponseParser added in v1.1.3

func NewMockErrorResponseParser(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockErrorResponseParser

NewMockErrorResponseParser creates a new instance of MockErrorResponseParser. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockErrorResponseParser) CanParse added in v1.1.3

func (_mock *MockErrorResponseParser) CanParse(body []byte) bool

CanParse provides a mock function for the type MockErrorResponseParser

func (*MockErrorResponseParser) EXPECT added in v1.1.3

func (*MockErrorResponseParser) Parse added in v1.1.3

func (_mock *MockErrorResponseParser) Parse(body []byte) (*ParsedErrorResponse, error)

Parse provides a mock function for the type MockErrorResponseParser

type MockErrorResponseParser_CanParse_Call added in v1.1.3

type MockErrorResponseParser_CanParse_Call struct {
	*mock.Call
}

MockErrorResponseParser_CanParse_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CanParse'

func (*MockErrorResponseParser_CanParse_Call) Return added in v1.1.3

func (*MockErrorResponseParser_CanParse_Call) Run added in v1.1.3

func (*MockErrorResponseParser_CanParse_Call) RunAndReturn added in v1.1.3

type MockErrorResponseParser_Expecter added in v1.1.3

type MockErrorResponseParser_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockErrorResponseParser_Expecter) CanParse added in v1.1.3

CanParse is a helper method to define mock.On call

  • body []byte

func (*MockErrorResponseParser_Expecter) Parse added in v1.1.3

Parse is a helper method to define mock.On call

  • body []byte

type MockErrorResponseParser_Parse_Call added in v1.1.3

type MockErrorResponseParser_Parse_Call struct {
	*mock.Call
}

MockErrorResponseParser_Parse_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Parse'

func (*MockErrorResponseParser_Parse_Call) Return added in v1.1.3

func (*MockErrorResponseParser_Parse_Call) Run added in v1.1.3

func (*MockErrorResponseParser_Parse_Call) RunAndReturn added in v1.1.3

type MockExecutor added in v1.1.3

type MockExecutor struct {
	mock.Mock
}

MockExecutor is an autogenerated mock type for the Executor type

func NewMockExecutor added in v1.1.3

func NewMockExecutor(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockExecutor

NewMockExecutor creates a new instance of MockExecutor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockExecutor) Delete added in v1.1.3

func (_mock *MockExecutor) Delete(ctx context.Context, path string) (*http.Response, error)

Delete provides a mock function for the type MockExecutor

func (*MockExecutor) DeleteJSON added in v1.1.3

func (_mock *MockExecutor) DeleteJSON(ctx context.Context, path string, result any) error

DeleteJSON provides a mock function for the type MockExecutor

func (*MockExecutor) Do added in v1.1.3

func (_mock *MockExecutor) Do(ctx context.Context, method string, path string, body any) (*http.Response, error)

Do provides a mock function for the type MockExecutor

func (*MockExecutor) DoWithResponse added in v1.1.3

func (_mock *MockExecutor) DoWithResponse(ctx context.Context, method string, path string, body any, result any) error

DoWithResponse provides a mock function for the type MockExecutor

func (*MockExecutor) EXPECT added in v1.1.3

func (_m *MockExecutor) EXPECT() *MockExecutor_Expecter

func (*MockExecutor) Get added in v1.1.3

func (_mock *MockExecutor) Get(ctx context.Context, path string) (*http.Response, error)

Get provides a mock function for the type MockExecutor

func (*MockExecutor) GetErrorParser added in v1.1.3

func (_mock *MockExecutor) GetErrorParser() *ErrorParserChain

GetErrorParser provides a mock function for the type MockExecutor

func (*MockExecutor) GetHTTPClient added in v1.1.3

func (_mock *MockExecutor) GetHTTPClient() *http.Client

GetHTTPClient provides a mock function for the type MockExecutor

func (*MockExecutor) GetJSON added in v1.1.3

func (_mock *MockExecutor) GetJSON(ctx context.Context, path string, result any) error

GetJSON provides a mock function for the type MockExecutor

func (*MockExecutor) Patch added in v1.1.3

func (_mock *MockExecutor) Patch(ctx context.Context, path string, body any) (*http.Response, error)

Patch provides a mock function for the type MockExecutor

func (*MockExecutor) PatchJSON added in v1.1.3

func (_mock *MockExecutor) PatchJSON(ctx context.Context, path string, body any, result any) error

PatchJSON provides a mock function for the type MockExecutor

func (*MockExecutor) Post added in v1.1.3

func (_mock *MockExecutor) Post(ctx context.Context, path string, body any) (*http.Response, error)

Post provides a mock function for the type MockExecutor

func (*MockExecutor) PostJSON added in v1.1.3

func (_mock *MockExecutor) PostJSON(ctx context.Context, path string, body any, result any) error

PostJSON provides a mock function for the type MockExecutor

func (*MockExecutor) Put added in v1.1.3

func (_mock *MockExecutor) Put(ctx context.Context, path string, body any) (*http.Response, error)

Put provides a mock function for the type MockExecutor

func (*MockExecutor) PutJSON added in v1.1.3

func (_mock *MockExecutor) PutJSON(ctx context.Context, path string, body any, result any) error

PutJSON provides a mock function for the type MockExecutor

func (*MockExecutor) RemoveHeader added in v1.1.3

func (_mock *MockExecutor) RemoveHeader(key string)

RemoveHeader provides a mock function for the type MockExecutor

func (*MockExecutor) SetBaseURL added in v1.1.3

func (_mock *MockExecutor) SetBaseURL(baseURL string)

SetBaseURL provides a mock function for the type MockExecutor

func (*MockExecutor) SetErrorParser added in v1.1.3

func (_mock *MockExecutor) SetErrorParser(parser *ErrorParserChain)

SetErrorParser provides a mock function for the type MockExecutor

func (*MockExecutor) SetHTTPClient added in v1.1.3

func (_mock *MockExecutor) SetHTTPClient(httpClient *http.Client)

SetHTTPClient provides a mock function for the type MockExecutor

func (*MockExecutor) SetHeader added in v1.1.3

func (_mock *MockExecutor) SetHeader(key string, value string)

SetHeader provides a mock function for the type MockExecutor

func (*MockExecutor) SetHeaders added in v1.1.3

func (_mock *MockExecutor) SetHeaders(headers map[string]string)

SetHeaders provides a mock function for the type MockExecutor

type MockExecutor_DeleteJSON_Call added in v1.1.3

type MockExecutor_DeleteJSON_Call struct {
	*mock.Call
}

MockExecutor_DeleteJSON_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteJSON'

func (*MockExecutor_DeleteJSON_Call) Return added in v1.1.3

func (*MockExecutor_DeleteJSON_Call) Run added in v1.1.3

func (*MockExecutor_DeleteJSON_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_DeleteJSON_Call) RunAndReturn(run func(ctx context.Context, path string, result any) error) *MockExecutor_DeleteJSON_Call

type MockExecutor_Delete_Call added in v1.1.3

type MockExecutor_Delete_Call struct {
	*mock.Call
}

MockExecutor_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete'

func (*MockExecutor_Delete_Call) Return added in v1.1.3

func (*MockExecutor_Delete_Call) Run added in v1.1.3

func (*MockExecutor_Delete_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_Delete_Call) RunAndReturn(run func(ctx context.Context, path string) (*http.Response, error)) *MockExecutor_Delete_Call

type MockExecutor_DoWithResponse_Call added in v1.1.3

type MockExecutor_DoWithResponse_Call struct {
	*mock.Call
}

MockExecutor_DoWithResponse_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DoWithResponse'

func (*MockExecutor_DoWithResponse_Call) Return added in v1.1.3

func (*MockExecutor_DoWithResponse_Call) Run added in v1.1.3

func (_c *MockExecutor_DoWithResponse_Call) Run(run func(ctx context.Context, method string, path string, body any, result any)) *MockExecutor_DoWithResponse_Call

func (*MockExecutor_DoWithResponse_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_DoWithResponse_Call) RunAndReturn(run func(ctx context.Context, method string, path string, body any, result any) error) *MockExecutor_DoWithResponse_Call

type MockExecutor_Do_Call added in v1.1.3

type MockExecutor_Do_Call struct {
	*mock.Call
}

MockExecutor_Do_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Do'

func (*MockExecutor_Do_Call) Return added in v1.1.3

func (_c *MockExecutor_Do_Call) Return(response *http.Response, err error) *MockExecutor_Do_Call

func (*MockExecutor_Do_Call) Run added in v1.1.3

func (_c *MockExecutor_Do_Call) Run(run func(ctx context.Context, method string, path string, body any)) *MockExecutor_Do_Call

func (*MockExecutor_Do_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_Do_Call) RunAndReturn(run func(ctx context.Context, method string, path string, body any) (*http.Response, error)) *MockExecutor_Do_Call

type MockExecutor_Expecter added in v1.1.3

type MockExecutor_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockExecutor_Expecter) Delete added in v1.1.3

func (_e *MockExecutor_Expecter) Delete(ctx interface{}, path interface{}) *MockExecutor_Delete_Call

Delete is a helper method to define mock.On call

  • ctx context.Context
  • path string

func (*MockExecutor_Expecter) DeleteJSON added in v1.1.3

func (_e *MockExecutor_Expecter) DeleteJSON(ctx interface{}, path interface{}, result interface{}) *MockExecutor_DeleteJSON_Call

DeleteJSON is a helper method to define mock.On call

  • ctx context.Context
  • path string
  • result any

func (*MockExecutor_Expecter) Do added in v1.1.3

func (_e *MockExecutor_Expecter) Do(ctx interface{}, method interface{}, path interface{}, body interface{}) *MockExecutor_Do_Call

Do is a helper method to define mock.On call

  • ctx context.Context
  • method string
  • path string
  • body any

func (*MockExecutor_Expecter) DoWithResponse added in v1.1.3

func (_e *MockExecutor_Expecter) DoWithResponse(ctx interface{}, method interface{}, path interface{}, body interface{}, result interface{}) *MockExecutor_DoWithResponse_Call

DoWithResponse is a helper method to define mock.On call

  • ctx context.Context
  • method string
  • path string
  • body any
  • result any

func (*MockExecutor_Expecter) Get added in v1.1.3

func (_e *MockExecutor_Expecter) Get(ctx interface{}, path interface{}) *MockExecutor_Get_Call

Get is a helper method to define mock.On call

  • ctx context.Context
  • path string

func (*MockExecutor_Expecter) GetErrorParser added in v1.1.3

GetErrorParser is a helper method to define mock.On call

func (*MockExecutor_Expecter) GetHTTPClient added in v1.1.3

GetHTTPClient is a helper method to define mock.On call

func (*MockExecutor_Expecter) GetJSON added in v1.1.3

func (_e *MockExecutor_Expecter) GetJSON(ctx interface{}, path interface{}, result interface{}) *MockExecutor_GetJSON_Call

GetJSON is a helper method to define mock.On call

  • ctx context.Context
  • path string
  • result any

func (*MockExecutor_Expecter) Patch added in v1.1.3

func (_e *MockExecutor_Expecter) Patch(ctx interface{}, path interface{}, body interface{}) *MockExecutor_Patch_Call

Patch is a helper method to define mock.On call

  • ctx context.Context
  • path string
  • body any

func (*MockExecutor_Expecter) PatchJSON added in v1.1.3

func (_e *MockExecutor_Expecter) PatchJSON(ctx interface{}, path interface{}, body interface{}, result interface{}) *MockExecutor_PatchJSON_Call

PatchJSON is a helper method to define mock.On call

  • ctx context.Context
  • path string
  • body any
  • result any

func (*MockExecutor_Expecter) Post added in v1.1.3

func (_e *MockExecutor_Expecter) Post(ctx interface{}, path interface{}, body interface{}) *MockExecutor_Post_Call

Post is a helper method to define mock.On call

  • ctx context.Context
  • path string
  • body any

func (*MockExecutor_Expecter) PostJSON added in v1.1.3

func (_e *MockExecutor_Expecter) PostJSON(ctx interface{}, path interface{}, body interface{}, result interface{}) *MockExecutor_PostJSON_Call

PostJSON is a helper method to define mock.On call

  • ctx context.Context
  • path string
  • body any
  • result any

func (*MockExecutor_Expecter) Put added in v1.1.3

func (_e *MockExecutor_Expecter) Put(ctx interface{}, path interface{}, body interface{}) *MockExecutor_Put_Call

Put is a helper method to define mock.On call

  • ctx context.Context
  • path string
  • body any

func (*MockExecutor_Expecter) PutJSON added in v1.1.3

func (_e *MockExecutor_Expecter) PutJSON(ctx interface{}, path interface{}, body interface{}, result interface{}) *MockExecutor_PutJSON_Call

PutJSON is a helper method to define mock.On call

  • ctx context.Context
  • path string
  • body any
  • result any

func (*MockExecutor_Expecter) RemoveHeader added in v1.1.3

func (_e *MockExecutor_Expecter) RemoveHeader(key interface{}) *MockExecutor_RemoveHeader_Call

RemoveHeader is a helper method to define mock.On call

  • key string

func (*MockExecutor_Expecter) SetBaseURL added in v1.1.3

func (_e *MockExecutor_Expecter) SetBaseURL(baseURL interface{}) *MockExecutor_SetBaseURL_Call

SetBaseURL is a helper method to define mock.On call

  • baseURL string

func (*MockExecutor_Expecter) SetErrorParser added in v1.1.3

func (_e *MockExecutor_Expecter) SetErrorParser(parser interface{}) *MockExecutor_SetErrorParser_Call

SetErrorParser is a helper method to define mock.On call

  • parser *ErrorParserChain

func (*MockExecutor_Expecter) SetHTTPClient added in v1.1.3

func (_e *MockExecutor_Expecter) SetHTTPClient(httpClient interface{}) *MockExecutor_SetHTTPClient_Call

SetHTTPClient is a helper method to define mock.On call

  • httpClient *http.Client

func (*MockExecutor_Expecter) SetHeader added in v1.1.3

func (_e *MockExecutor_Expecter) SetHeader(key interface{}, value interface{}) *MockExecutor_SetHeader_Call

SetHeader is a helper method to define mock.On call

  • key string
  • value string

func (*MockExecutor_Expecter) SetHeaders added in v1.1.3

func (_e *MockExecutor_Expecter) SetHeaders(headers interface{}) *MockExecutor_SetHeaders_Call

SetHeaders is a helper method to define mock.On call

  • headers map[string]string

type MockExecutor_GetErrorParser_Call added in v1.1.3

type MockExecutor_GetErrorParser_Call struct {
	*mock.Call
}

MockExecutor_GetErrorParser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetErrorParser'

func (*MockExecutor_GetErrorParser_Call) Return added in v1.1.3

func (*MockExecutor_GetErrorParser_Call) Run added in v1.1.3

func (*MockExecutor_GetErrorParser_Call) RunAndReturn added in v1.1.3

type MockExecutor_GetHTTPClient_Call added in v1.1.3

type MockExecutor_GetHTTPClient_Call struct {
	*mock.Call
}

MockExecutor_GetHTTPClient_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetHTTPClient'

func (*MockExecutor_GetHTTPClient_Call) Return added in v1.1.3

func (*MockExecutor_GetHTTPClient_Call) Run added in v1.1.3

func (*MockExecutor_GetHTTPClient_Call) RunAndReturn added in v1.1.3

type MockExecutor_GetJSON_Call added in v1.1.3

type MockExecutor_GetJSON_Call struct {
	*mock.Call
}

MockExecutor_GetJSON_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetJSON'

func (*MockExecutor_GetJSON_Call) Return added in v1.1.3

func (*MockExecutor_GetJSON_Call) Run added in v1.1.3

func (_c *MockExecutor_GetJSON_Call) Run(run func(ctx context.Context, path string, result any)) *MockExecutor_GetJSON_Call

func (*MockExecutor_GetJSON_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_GetJSON_Call) RunAndReturn(run func(ctx context.Context, path string, result any) error) *MockExecutor_GetJSON_Call

type MockExecutor_Get_Call added in v1.1.3

type MockExecutor_Get_Call struct {
	*mock.Call
}

MockExecutor_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get'

func (*MockExecutor_Get_Call) Return added in v1.1.3

func (_c *MockExecutor_Get_Call) Return(response *http.Response, err error) *MockExecutor_Get_Call

func (*MockExecutor_Get_Call) Run added in v1.1.3

func (_c *MockExecutor_Get_Call) Run(run func(ctx context.Context, path string)) *MockExecutor_Get_Call

func (*MockExecutor_Get_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_Get_Call) RunAndReturn(run func(ctx context.Context, path string) (*http.Response, error)) *MockExecutor_Get_Call

type MockExecutor_PatchJSON_Call added in v1.1.3

type MockExecutor_PatchJSON_Call struct {
	*mock.Call
}

MockExecutor_PatchJSON_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PatchJSON'

func (*MockExecutor_PatchJSON_Call) Return added in v1.1.3

func (*MockExecutor_PatchJSON_Call) Run added in v1.1.3

func (_c *MockExecutor_PatchJSON_Call) Run(run func(ctx context.Context, path string, body any, result any)) *MockExecutor_PatchJSON_Call

func (*MockExecutor_PatchJSON_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_PatchJSON_Call) RunAndReturn(run func(ctx context.Context, path string, body any, result any) error) *MockExecutor_PatchJSON_Call

type MockExecutor_Patch_Call added in v1.1.3

type MockExecutor_Patch_Call struct {
	*mock.Call
}

MockExecutor_Patch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Patch'

func (*MockExecutor_Patch_Call) Return added in v1.1.3

func (*MockExecutor_Patch_Call) Run added in v1.1.3

func (_c *MockExecutor_Patch_Call) Run(run func(ctx context.Context, path string, body any)) *MockExecutor_Patch_Call

func (*MockExecutor_Patch_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_Patch_Call) RunAndReturn(run func(ctx context.Context, path string, body any) (*http.Response, error)) *MockExecutor_Patch_Call

type MockExecutor_PostJSON_Call added in v1.1.3

type MockExecutor_PostJSON_Call struct {
	*mock.Call
}

MockExecutor_PostJSON_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostJSON'

func (*MockExecutor_PostJSON_Call) Return added in v1.1.3

func (*MockExecutor_PostJSON_Call) Run added in v1.1.3

func (_c *MockExecutor_PostJSON_Call) Run(run func(ctx context.Context, path string, body any, result any)) *MockExecutor_PostJSON_Call

func (*MockExecutor_PostJSON_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_PostJSON_Call) RunAndReturn(run func(ctx context.Context, path string, body any, result any) error) *MockExecutor_PostJSON_Call

type MockExecutor_Post_Call added in v1.1.3

type MockExecutor_Post_Call struct {
	*mock.Call
}

MockExecutor_Post_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Post'

func (*MockExecutor_Post_Call) Return added in v1.1.3

func (_c *MockExecutor_Post_Call) Return(response *http.Response, err error) *MockExecutor_Post_Call

func (*MockExecutor_Post_Call) Run added in v1.1.3

func (_c *MockExecutor_Post_Call) Run(run func(ctx context.Context, path string, body any)) *MockExecutor_Post_Call

func (*MockExecutor_Post_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_Post_Call) RunAndReturn(run func(ctx context.Context, path string, body any) (*http.Response, error)) *MockExecutor_Post_Call

type MockExecutor_PutJSON_Call added in v1.1.3

type MockExecutor_PutJSON_Call struct {
	*mock.Call
}

MockExecutor_PutJSON_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PutJSON'

func (*MockExecutor_PutJSON_Call) Return added in v1.1.3

func (*MockExecutor_PutJSON_Call) Run added in v1.1.3

func (_c *MockExecutor_PutJSON_Call) Run(run func(ctx context.Context, path string, body any, result any)) *MockExecutor_PutJSON_Call

func (*MockExecutor_PutJSON_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_PutJSON_Call) RunAndReturn(run func(ctx context.Context, path string, body any, result any) error) *MockExecutor_PutJSON_Call

type MockExecutor_Put_Call added in v1.1.3

type MockExecutor_Put_Call struct {
	*mock.Call
}

MockExecutor_Put_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Put'

func (*MockExecutor_Put_Call) Return added in v1.1.3

func (_c *MockExecutor_Put_Call) Return(response *http.Response, err error) *MockExecutor_Put_Call

func (*MockExecutor_Put_Call) Run added in v1.1.3

func (_c *MockExecutor_Put_Call) Run(run func(ctx context.Context, path string, body any)) *MockExecutor_Put_Call

func (*MockExecutor_Put_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_Put_Call) RunAndReturn(run func(ctx context.Context, path string, body any) (*http.Response, error)) *MockExecutor_Put_Call

type MockExecutor_RemoveHeader_Call added in v1.1.3

type MockExecutor_RemoveHeader_Call struct {
	*mock.Call
}

MockExecutor_RemoveHeader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveHeader'

func (*MockExecutor_RemoveHeader_Call) Return added in v1.1.3

func (*MockExecutor_RemoveHeader_Call) Run added in v1.1.3

func (*MockExecutor_RemoveHeader_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_RemoveHeader_Call) RunAndReturn(run func(key string)) *MockExecutor_RemoveHeader_Call

type MockExecutor_SetBaseURL_Call added in v1.1.3

type MockExecutor_SetBaseURL_Call struct {
	*mock.Call
}

MockExecutor_SetBaseURL_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetBaseURL'

func (*MockExecutor_SetBaseURL_Call) Return added in v1.1.3

func (*MockExecutor_SetBaseURL_Call) Run added in v1.1.3

func (*MockExecutor_SetBaseURL_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_SetBaseURL_Call) RunAndReturn(run func(baseURL string)) *MockExecutor_SetBaseURL_Call

type MockExecutor_SetErrorParser_Call added in v1.1.3

type MockExecutor_SetErrorParser_Call struct {
	*mock.Call
}

MockExecutor_SetErrorParser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetErrorParser'

func (*MockExecutor_SetErrorParser_Call) Return added in v1.1.3

func (*MockExecutor_SetErrorParser_Call) Run added in v1.1.3

func (*MockExecutor_SetErrorParser_Call) RunAndReturn added in v1.1.3

type MockExecutor_SetHTTPClient_Call added in v1.1.3

type MockExecutor_SetHTTPClient_Call struct {
	*mock.Call
}

MockExecutor_SetHTTPClient_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetHTTPClient'

func (*MockExecutor_SetHTTPClient_Call) Return added in v1.1.3

func (*MockExecutor_SetHTTPClient_Call) Run added in v1.1.3

func (*MockExecutor_SetHTTPClient_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_SetHTTPClient_Call) RunAndReturn(run func(httpClient *http.Client)) *MockExecutor_SetHTTPClient_Call

type MockExecutor_SetHeader_Call added in v1.1.3

type MockExecutor_SetHeader_Call struct {
	*mock.Call
}

MockExecutor_SetHeader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetHeader'

func (*MockExecutor_SetHeader_Call) Return added in v1.1.3

func (*MockExecutor_SetHeader_Call) Run added in v1.1.3

func (*MockExecutor_SetHeader_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_SetHeader_Call) RunAndReturn(run func(key string, value string)) *MockExecutor_SetHeader_Call

type MockExecutor_SetHeaders_Call added in v1.1.3

type MockExecutor_SetHeaders_Call struct {
	*mock.Call
}

MockExecutor_SetHeaders_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetHeaders'

func (*MockExecutor_SetHeaders_Call) Return added in v1.1.3

func (*MockExecutor_SetHeaders_Call) Run added in v1.1.3

func (*MockExecutor_SetHeaders_Call) RunAndReturn added in v1.1.3

func (_c *MockExecutor_SetHeaders_Call) RunAndReturn(run func(headers map[string]string)) *MockExecutor_SetHeaders_Call

type ParsedErrorResponse added in v1.1.0

type ParsedErrorResponse struct {
	Message       string
	ErrorCode     string
	CorrelationID string
	Details       map[string]interface{}
}

ParsedErrorResponse represents a parsed error response from an external API

type RFC7807ErrorParser added in v1.1.0

type RFC7807ErrorParser struct {
	GenericErrorParser
}

RFC7807ErrorParser parses RFC 7807 Problem Details for HTTP APIs

func (*RFC7807ErrorParser) CanParse added in v1.1.0

func (p *RFC7807ErrorParser) CanParse(body []byte) bool

func (*RFC7807ErrorParser) Parse added in v1.1.0

func (p *RFC7807ErrorParser) Parse(body []byte) (*ParsedErrorResponse, error)

type RateLimiterConfig added in v1.3.0

type RateLimiterConfig struct {
	Enabled       bool
	MaxExecutions uint
	Period        time.Duration
	MaxWaitTime   time.Duration
	IsBursty      bool // If true, uses fixed window; else uses smooth leaky bucket
}

RateLimiterConfig holds rate limiter configuration

type ResilienceBuilder

type ResilienceBuilder struct {
	// contains filtered or unexported fields
}

ResilienceBuilder builds resilience configurations using fluent API

func NewResilienceBuilder

func NewResilienceBuilder() *ResilienceBuilder

NewResilienceBuilder creates a new resilience configuration builder

func (*ResilienceBuilder) Build

func (rb *ResilienceBuilder) Build() *ResilienceConfig

Build constructs the final resilience configuration

func (*ResilienceBuilder) WithAdaptiveThrottler added in v1.3.0

func (rb *ResilienceBuilder) WithAdaptiveThrottler(cfg *AdaptiveThrottlerConfig) *ResilienceBuilder

func (*ResilienceBuilder) WithBulkhead added in v1.3.0

func (rb *ResilienceBuilder) WithBulkhead(cfg *BulkheadConfig) *ResilienceBuilder

func (*ResilienceBuilder) WithCache added in v1.3.0

func (rb *ResilienceBuilder) WithCache(cfg *CacheConfig) *ResilienceBuilder

func (*ResilienceBuilder) WithCircuitBreaker

func (rb *ResilienceBuilder) WithCircuitBreaker(cfg *CircuitBreakerConfig) *ResilienceBuilder

WithCircuitBreaker configures circuit breaker settings

func (*ResilienceBuilder) WithFallback

func (rb *ResilienceBuilder) WithFallback(cfg *FallbackConfig) *ResilienceBuilder

WithFallback configures fallback settings

func (*ResilienceBuilder) WithHedge added in v1.3.0

func (rb *ResilienceBuilder) WithHedge(cfg *HedgeConfig) *ResilienceBuilder

func (*ResilienceBuilder) WithRateLimiter added in v1.3.0

func (rb *ResilienceBuilder) WithRateLimiter(cfg *RateLimiterConfig) *ResilienceBuilder

func (*ResilienceBuilder) WithRetryPolicy

func (rb *ResilienceBuilder) WithRetryPolicy(cfg *RetryPolicyConfig) *ResilienceBuilder

WithRetryPolicy configures retry policy settings

func (*ResilienceBuilder) WithTimeout

func (rb *ResilienceBuilder) WithTimeout(cfg *TimeoutConfig) *ResilienceBuilder

WithTimeout configures timeout settings

type ResilienceConfig

type ResilienceConfig struct {
	CircuitBreaker    *CircuitBreakerConfig
	RetryPolicy       *RetryPolicyConfig
	Timeout           *TimeoutConfig
	Fallback          *FallbackConfig
	RateLimiter       *RateLimiterConfig
	Bulkhead          *BulkheadConfig
	Hedge             *HedgeConfig
	AdaptiveThrottler *AdaptiveThrottlerConfig
	Cache             *CacheConfig
}

ResilienceConfig updated with new policies

func DefaultResilienceConfig

func DefaultResilienceConfig() *ResilienceConfig

DefaultResilienceConfig returns a production-ready default configuration

type RetryPolicyConfig

type RetryPolicyConfig struct {
	Enabled           bool
	MaxAttempts       int           // Maximum number of execution attempts (initial + retries)
	MaxRetries        int           // Maximum number of retries (MaxAttempts - 1)
	MaxDuration       time.Duration // Maximum total duration for all attempts
	Delay             time.Duration // Fixed delay between retries
	BackoffInitial    time.Duration // Initial delay for exponential backoff
	BackoffMax        time.Duration // Maximum delay for exponential backoff
	RandomDelayMin    time.Duration // Minimum random delay
	RandomDelayMax    time.Duration // Maximum random delay
	JitterFactor      float64       // Jitter factor (0-1) to add randomness to delays
	Jitter            time.Duration // Time-based jitter to add to delays
	RetryableStatus   []int         // HTTP status codes that should trigger a retry
	AbortOnStatus     []int         // HTTP status codes that should abort retries immediately
	OnRetry           func(event failsafe.ExecutionEvent[*http.Response])
	OnRetriesExceeded func(event failsafe.ExecutionEvent[*http.Response])
	OnAbort           func(event failsafe.ExecutionEvent[*http.Response])
}

RetryPolicyConfig holds retry policy configuration

type StripeErrorParser added in v1.1.0

type StripeErrorParser struct {
	GenericErrorParser
}

StripeErrorParser parses Stripe-specific error responses

func (*StripeErrorParser) CanParse added in v1.1.0

func (p *StripeErrorParser) CanParse(body []byte) bool

func (*StripeErrorParser) Parse added in v1.1.0

func (p *StripeErrorParser) Parse(body []byte) (*ParsedErrorResponse, error)

type SumsubErrorParser added in v1.1.0

type SumsubErrorParser struct {
	GenericErrorParser
}

SumsubErrorParser parses Sumsub-specific error responses

func (*SumsubErrorParser) CanParse added in v1.1.0

func (p *SumsubErrorParser) CanParse(body []byte) bool

func (*SumsubErrorParser) Parse added in v1.1.0

func (p *SumsubErrorParser) Parse(body []byte) (*ParsedErrorResponse, error)

type ThresholdRatio

type ThresholdRatio struct {
	Failures uint // Number of failures
	Total    uint // Total executions
}

ThresholdRatio represents a ratio-based threshold (e.g., 3 failures out of 5 total)

type TimeoutConfig

type TimeoutConfig struct {
	Enabled           bool
	Duration          time.Duration // Maximum time allowed for execution
	OnTimeoutExceeded func(event failsafe.ExecutionDoneEvent[*http.Response])
}

TimeoutConfig holds timeout configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL