Documentation
¶
Overview ¶
Package clientx provides shared client-side reliability helpers.
Index ¶
- Variables
- func CodeOf(err error) int
- func Do(ctx context.Context, cfg RetryConfig, fn func(context.Context) error) error
- func IsRetryable(err error) bool
- func MapGRPCError(err error) error
- func NewError(code int, message string, err error) error
- type Breaker
- type BreakerConfig
- type BreakerState
- type ClientError
- type HTTPClient
- type HTTPClientConfig
- type HTTPStatusError
- type RetryConfig
Constants ¶
This section is empty.
Variables ¶
var ErrCircuitOpen = errors.New("circuit breaker open")
var ErrNilOperation = errors.New("clientx: operation is nil")
var ErrRequestBodyTooLarge = errors.New("clientx: request body exceeds configured limit")
var ErrResponseBodyTooLarge = errors.New("clientx: response body exceeds configured limit")
Functions ¶
func IsRetryable ¶
IsRetryable reports whether err is generally safe to retry.
func MapGRPCError ¶
MapGRPCError maps gRPC errors to standard response codes.
Types ¶
type Breaker ¶
type Breaker struct {
// contains filtered or unexported fields
}
Breaker is a small client-side circuit breaker.
func (*Breaker) State ¶
func (b *Breaker) State() BreakerState
State returns the current breaker state.
type BreakerConfig ¶
type BreakerConfig struct {
Name string
FailureThreshold int
Cooldown time.Duration
Now func() time.Time
ShouldCount func(error) bool
}
BreakerConfig configures a circuit breaker.
type BreakerState ¶
type BreakerState int
const ( BreakerClosed BreakerState = iota BreakerOpen BreakerHalfOpen )
type ClientError ¶
ClientError is a normalized outbound service call error.
func (*ClientError) Error ¶
func (e *ClientError) Error() string
func (*ClientError) Unwrap ¶
func (e *ClientError) Unwrap() error
type HTTPClient ¶ added in v0.13.0
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient applies timeout, retry, circuit breaking and trace propagation consistently to outbound HTTP calls.
func NewHTTPClient ¶ added in v0.13.0
func NewHTTPClient(cfg HTTPClientConfig) *HTTPClient
NewHTTPClient creates a governed HTTP client. The default retry policy only retries idempotent methods and transient transport/status failures.
type HTTPClientConfig ¶ added in v0.13.0
type HTTPClientConfig struct {
Client *http.Client
Timeout time.Duration
Retry RetryConfig
Breaker *Breaker
Telemetry *telemetry.Provider
ServiceName string
RetryNonIdempotent bool
MaxBodyBytes int64
// MaxResponseBodyBytes bounds successful response bodies returned to the
// caller; zero uses a 10 MiB default.
MaxResponseBodyBytes int64
}
HTTPClientConfig configures the shared outbound HTTP client.
type HTTPStatusError ¶ added in v0.13.0
HTTPStatusError reports a non-success HTTP response after request execution.
func (*HTTPStatusError) Error ¶ added in v0.13.0
func (e *HTTPStatusError) Error() string
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int
// Budget bounds the entire retry operation, including backoff sleeps.
// Zero uses the caller's context without an additional deadline.
Budget time.Duration
InitialBackoff time.Duration
MaxBackoff time.Duration
Multiplier float64
Retryable func(error) bool
Sleep func(context.Context, time.Duration) error
JitterFraction float64
DisableJitter bool
}
RetryConfig configures retry behavior for outbound service calls.