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 RetryConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrCircuitOpen = errors.New("circuit breaker open")
View Source
var ErrNilOperation = errors.New("clientx: operation is nil")
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 {
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 RetryConfig ¶
type RetryConfig struct {
MaxAttempts int
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.
Click to show internal directories.
Click to hide internal directories.