28 lines
958 B
Go
28 lines
958 B
Go
// Package circuitbreaker provides a per-host circuit breaker as HTTP middleware.
|
|
//
|
|
// The circuit breaker monitors request failures and temporarily blocks requests
|
|
// to unhealthy hosts, allowing them time to recover before retrying.
|
|
//
|
|
// # State machine
|
|
//
|
|
// - Closed — normal operation, requests pass through
|
|
// - Open — too many failures, requests are rejected with ErrCircuitOpen
|
|
// - HalfOpen — after a cooldown period, one probe request is allowed through
|
|
//
|
|
// # Usage
|
|
//
|
|
// mw := circuitbreaker.Transport(
|
|
// circuitbreaker.WithThreshold(5),
|
|
// circuitbreaker.WithTimeout(30 * time.Second),
|
|
// )
|
|
// transport := mw(http.DefaultTransport)
|
|
//
|
|
// The circuit breaker is per-host: each unique request host gets its own
|
|
// independent breaker state machine stored in a sync.Map.
|
|
//
|
|
// # Sentinel errors
|
|
//
|
|
// ErrCircuitOpen is returned when a request is rejected because the circuit
|
|
// is in the Open state.
|
|
package circuitbreaker
|