engine

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(config *Config) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Delete

func (c *Client) Delete(url string, options ...RequestOption) (*Response, error)

func (*Client) Get

func (c *Client) Get(url string, options ...RequestOption) (*Response, error)

func (*Client) GetHealthStatus added in v1.1.0

func (c *Client) GetHealthStatus() HealthStatus

func (*Client) Head

func (c *Client) Head(url string, options ...RequestOption) (*Response, error)

func (*Client) IsHealthy added in v1.1.0

func (c *Client) IsHealthy() bool

func (*Client) Options

func (c *Client) Options(url string, options ...RequestOption) (*Response, error)

func (*Client) Patch

func (c *Client) Patch(url string, options ...RequestOption) (*Response, error)

func (*Client) Post

func (c *Client) Post(url string, options ...RequestOption) (*Response, error)

func (*Client) Put

func (c *Client) Put(url string, options ...RequestOption) (*Response, error)

func (*Client) Request

func (c *Client) Request(ctx context.Context, method, url string, options ...RequestOption) (*Response, error)

type ClientError

type ClientError struct {
	Type       ErrorType
	Message    string
	Cause      error
	URL        string
	Method     string
	Attempts   int
	StatusCode int    // HTTP status code if applicable
	Host       string // Host for circuit breaker errors
}

func ClassifyError

func ClassifyError(err error, reqURL, method string, attempts int) *ClientError

func (*ClientError) Code

func (e *ClientError) Code() string

func (*ClientError) Error

func (e *ClientError) Error() string

func (*ClientError) IsRetryable

func (e *ClientError) IsRetryable() bool

func (*ClientError) Unwrap

func (e *ClientError) Unwrap() error

type Config

type Config struct {
	Timeout               time.Duration
	DialTimeout           time.Duration
	KeepAlive             time.Duration
	TLSHandshakeTimeout   time.Duration
	ResponseHeaderTimeout time.Duration
	IdleConnTimeout       time.Duration
	MaxIdleConns          int
	MaxIdleConnsPerHost   int
	MaxConnsPerHost       int
	ProxyURL              string

	TLSConfig           any
	MinTLSVersion       uint16
	MaxTLSVersion       uint16
	InsecureSkipVerify  bool
	MaxResponseBodySize int64
	ValidateURL         bool
	ValidateHeaders     bool
	AllowPrivateIPs     bool
	StrictContentLength bool

	MaxRetries    int
	RetryDelay    time.Duration
	MaxRetryDelay time.Duration
	BackoffFactor float64
	Jitter        bool

	UserAgent       string
	Headers         map[string]string
	FollowRedirects bool
	MaxRedirects    int
	EnableHTTP2     bool

	CookieJar     any
	EnableCookies bool
}

Config defines the HTTP client configuration. Config should be treated as immutable after creation.

type ErrorType

type ErrorType int
const (
	ErrorTypeUnknown ErrorType = iota
	ErrorTypeNetwork
	ErrorTypeTimeout
	ErrorTypeContextCanceled
	ErrorTypeResponseRead
	ErrorTypeTransport
	ErrorTypeRetryExhausted
	ErrorTypeTLS
	ErrorTypeCertificate
	ErrorTypeDNS
	ErrorTypeValidation
	ErrorTypeHTTP
)

type FileDataExtractor

type FileDataExtractor struct {
	Filename    string
	Content     []byte
	ContentType string
}

type FormDataExtractor

type FormDataExtractor struct {
	Fields map[string]string
	Files  map[string]*FileDataExtractor
}

type HealthStatus added in v1.2.0

type HealthStatus struct {
	Healthy            bool
	TotalRequests      int64
	SuccessfulRequests int64
	FailedRequests     int64
	AverageLatency     time.Duration
	ErrorRate          float64
}

HealthStatus represents basic health metrics

type Request

type Request struct {
	Method          string
	URL             string
	Headers         map[string]string
	QueryParams     map[string]any
	Body            any
	Timeout         time.Duration
	MaxRetries      int
	Context         context.Context
	Cookies         []http.Cookie
	FollowRedirects *bool
	MaxRedirects    *int
}

type RequestOption

type RequestOption func(*Request) error

type RequestProcessor

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

func NewRequestProcessor

func NewRequestProcessor(config *Config) *RequestProcessor

func (*RequestProcessor) Build

func (p *RequestProcessor) Build(req *Request) (*http.Request, error)

type Response

type Response struct {
	StatusCode     int
	Status         string
	Headers        map[string][]string
	Body           string
	RawBody        []byte
	ContentLength  int64
	Proto          string
	Duration       time.Duration
	Attempts       int
	Cookies        []*http.Cookie
	RedirectChain  []string
	RedirectCount  int
	RequestHeaders map[string][]string // Actual headers sent with the request
}

Response represents an HTTP response. Response objects are safe to read from multiple goroutines after they are returned.

type ResponseProcessor

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

func NewResponseProcessor

func NewResponseProcessor(config *Config) *ResponseProcessor

func (*ResponseProcessor) Process

func (p *ResponseProcessor) Process(httpResp *http.Response) (*Response, error)

type RetryEngine

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

func NewRetryEngine

func NewRetryEngine(config *Config) *RetryEngine

func (*RetryEngine) GetDelay

func (r *RetryEngine) GetDelay(attempt int) time.Duration

func (*RetryEngine) GetDelayWithResponse added in v1.1.0

func (r *RetryEngine) GetDelayWithResponse(attempt int, resp *Response) time.Duration

func (*RetryEngine) MaxRetries

func (r *RetryEngine) MaxRetries() int

func (*RetryEngine) ShouldRetry

func (r *RetryEngine) ShouldRetry(resp *Response, err error, attempt int) bool

type Transport

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

Transport manages HTTP transport with comprehensive security and optimal performance

func NewTransport

func NewTransport(config *Config, pool *connection.PoolManager) (*Transport, error)

NewTransport creates a new transport manager with connection pool

func (*Transport) Close

func (t *Transport) Close() error

Close closes the transport and cleans up resources

func (*Transport) GetRedirectChain added in v1.3.0

func (t *Transport) GetRedirectChain() []string

GetRedirectChain returns the redirect chain and resets it

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes an HTTP round trip

func (*Transport) SetRedirectPolicy added in v1.3.0

func (t *Transport) SetRedirectPolicy(followRedirects bool, maxRedirects int)

SetRedirectPolicy updates the redirect policy for a specific request

Jump to

Keyboard shortcuts

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