Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrTooManyRequests is returned when the CB state is half open and the requests count is over the cb maxRequests ErrTooManyRequests = errors.New("INFRASTRUCTURE.CIRCUIT_BREAKER.STAGE_HALF_OPEN.TOO_MANY_REQUESTS.ERROR") // ErrOpenState is returned when the CB state is open ErrOpenState = errors.New("INFRASTRUCTURE.CIRCUIT_BREAKER.STAGE_OPEN.OPENED.ERROR") ErrStageChange = errors.New("INFRASTRUCTURE.CIRCUIT_BREAKER.STAGE.CHANGE.ERROR") )
View Source
var DefaultConfig = &Config{ Close: Close{CleanupInterval: 600000}, Half: Half{PassthroughRequests: 10}, Open: Open{ Duration: 1800000, Conditions: OpenConditions{ErrorConsecutive: 10, ErrorRatio: 0.5}, }, }
Functions ¶
func Do ¶
func Do[T any](cb CircuitBreaker, cmd string, onHandle Handler, onError ErrorHandler) (*T, error)
Types ¶
type CircuitBreaker ¶
type CircuitBreaker interface {
Do(cmd string, onHandle Handler, onError ErrorHandler) (any, error)
}
type Close ¶
type Close struct {
CleanupInterval int `json:"cleanup_interval" yaml:"cleanup_interval" mapstructure:"cleanup_interval"`
}
type Config ¶
type ErrorHandler ¶
type Half ¶
type Half struct {
PassthroughRequests uint32 `json:"passthrough_requests" yaml:"passthrough_requests" mapstructure:"passthrough_requests"`
}
type Open ¶
type Open struct { Duration int64 `json:"duration" yaml:"duration" mapstructure:"duration"` Conditions OpenConditions `json:"conditions" yaml:"conditions" mapstructure:"conditions"` }
type OpenConditions ¶
type OpenConditions struct { ErrorConsecutive uint32 `json:"error_consecutive" yaml:"error_consecutive" mapstructure:"error_consecutive"` ErrorRatio float32 `json:"error_ratio" yaml:"error_ratio" mapstructure:"error_ratio"` }
func (*OpenConditions) Validate ¶
func (conf *OpenConditions) Validate() error
Click to show internal directories.
Click to hide internal directories.