clients

package
v0.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

clients

Go-commons clients is a versatile client library written in Go that provides a unified interface for interacting with various services with the aim of common set of features like circuit breaker and retry handler. It allows you to communicate with different types of services, including REST APIs and messaging systems along using a consistent and easy-to-use interface.



Features

The Generic Golang Client offers the following features:

  1. Modularity: The client is designed with a modular architecture, allowing you to use specific sub-clients for different types of services.
  2. Sub-clients: The library provides sub-clients for interacting with different services, including REST, messaging, and more. You can selectively import and use the required sub-client(s) based on your needs.
Sub-clients

The Generic Golang Client includes the following sub-clients:

  1. REST Client
    The REST client enables communication with RESTful APIs. It provides methods for making HTTP requests, handling responses, and managing authentication.
  2. Messaging Client
    The messaging client allows you to interact with messaging systems such as RabbitMQ or Apache Kafka. It provides functionality for sending and receiving messages, managing message queues, and handling message processing.

Getting Started

To start using the Generic Golang Client, follow these steps:

  1. Install Go and set up your Go development environment.
  2. Import the Generic Golang Client into your project:
    import "go.nandlabs.io/commons/clients"
    
  3. Depending on the service you want to interact with, import the relevant sub-client:
    import "go.nandlabs.io/commons/clients/rest"
    
    or
    import "go.nandlabs.io/commons/clients/messaging"
    
    You can import multiple sub-clients if needed.
  4. Initialize the sub-client and start using its functionality. Refer to the sub-client's documentation for detailed instructions on how to use it.
Documentation

For detailed information on how to use the Generic Golang Client and its sub-clients, refer to the following documentation:

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

View Source
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.

type RetryInfo

type RetryInfo struct {
	MaxRetries int // Maximum number of retries allowed.
	Wait       int // Wait time in milliseconds between retries.
}

RetryInfo represents the retry configuration for a client.

Directories

Path Synopsis
Example usage:
Example usage:
Package rest provides a set of utilities for making RESTful API calls.
Package rest provides a set of utilities for making RESTful API calls.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL