Documentation ¶
Overview ¶
Package clients provides a collection of client libraries for various services. It offers a set of reusable and easy-to-use client implementations that can be used to interact with different services. These client libraries are designed to simplify the process of making requests, handling responses, and managing authentication for the respective services. The package includes clients for services such as HTTP, database, messaging, storage, and more. Each client library is organized into its own subpackage, making it easy to import and use only the necessary clients. Additionally, the package provides a consistent and unified interface for all the client libraries, allowing developers to switch between different services seamlessly. By using the clients package, developers can save time and effort by leveraging pre-built client implementations and focusing on the core logic of their applications. For more information and usage examples, refer to the documentation of each individual client library. These clients can be used to interact with the corresponding services and perform operations such as making API calls, retrieving data, and more.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CBOpenErr = errors.New("the Circuit breaker is open and unable to process request")
CBOpenErr is the error returned when the circuit breaker is open and unable to process requests.
Functions ¶
This section is empty.
Types ¶
type BreakerInfo ¶
type BreakerInfo struct { FailureThreshold uint64 // Number of consecutive failures required to open the circuit SuccessThreshold uint64 // Number of consecutive successes required to close the circuit MaxHalfOpen uint32 // Maximum number of requests allowed in the half-open state Timeout uint32 // Timeout duration for the circuit to transition from open to half-open state }
BreakerInfo holds the configuration parameters for the CircuitBreaker.
type CircuitBreaker ¶
type CircuitBreaker struct { *BreakerInfo // contains filtered or unexported fields }
CircuitBreaker is a struct that represents a circuit breaker.
func NewCB ¶
func NewCB(info *BreakerInfo) (cb *CircuitBreaker)
NewCB creates a new CircuitBreaker instance with the provided BreakerInfo. If no BreakerInfo is provided, default values will be used.
func (*CircuitBreaker) CanExecute ¶
func (cb *CircuitBreaker) CanExecute() (err error)
CanExecute checks if a request can be executed based on the current state of the circuit breaker. It returns an error if the circuit is open or if the maximum number of requests in the half-open state is reached.
func (*CircuitBreaker) OnExecution ¶
func (cb *CircuitBreaker) OnExecution(success bool)
OnExecution is called after a request is executed. It updates the success or failure counters based on the result of the request. It also checks if the circuit needs to transition to a different state based on the counters and thresholds.
func (*CircuitBreaker) Reset ¶
func (cb *CircuitBreaker) Reset()
Reset resets the circuit breaker to its initial state.