chttp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_RETRY_COUNT         = 1
	DEFAULT_RETRY_BACKOFF       = 500 * time.Millisecond
	DEFAULT_BREAKER_INTERVAL    = 10 * time.Second
	DEFAULT_BREAKER_TIMEOUT     = 10 * time.Second
	DEFAULT_BREAKER_PREFIX_NAME = "default"
	DEFAULT_BREAKER_MAX_REQUEST = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BreakerSettings

type BreakerSettings struct {
	Name          string                                                      `json:"name"`
	MaxRequests   uint32                                                      `json:"max-request"`
	Interval      time.Duration                                               `json:"interval"`
	Timeout       time.Duration                                               `json:"timeout"`
	ReadyToTrip   func(counts gobreaker.Counts) bool                          `json:"-"`
	OnStateChange func(name string, from gobreaker.State, to gobreaker.State) `json:"-"`
	IsSuccessful  func(err error) bool                                        `json:"-"`
}

Settings configures CircuitBreaker:

Name is the name of the CircuitBreaker.

MaxRequests is the maximum number of requests allowed to pass through when the CircuitBreaker is half-open. If MaxRequests is 0, the CircuitBreaker allows only 1 request.

Interval is the cyclic period of the closed state for the CircuitBreaker to clear the internal Counts. If Interval is less than or equal to 0, the CircuitBreaker doesn't clear internal Counts during the closed state.

Timeout is the period of the open state, after which the state of the CircuitBreaker becomes half-open. If Timeout is less than or equal to 0, the timeout value of the CircuitBreaker is set to 60 seconds.

ReadyToTrip is called with a copy of Counts whenever a request fails in the closed state. If ReadyToTrip returns true, the CircuitBreaker will be placed into the open state. If ReadyToTrip is nil, default ReadyToTrip is used. Default ReadyToTrip returns true when the number of consecutive failures is more than 5.

OnStateChange is called whenever the state of the CircuitBreaker changes.

IsSuccessful is called with the error returned from a request. If IsSuccessful returns true, the error is counted as a success. Otherwise the error is counted as a failure. If IsSuccessful is nil, default IsSuccessful is used, which returns false for all non-nil errors.

type HttpClient

type HttpClient interface {
	GetClient() *http.Client
	GetSettings() *Settings
}

func New

func New(settings *Settings) HttpClient

type RetrySettings

type RetrySettings struct {
	Retry       uint                             `json:"retry"`
	ShouldRetry func(error, *http.Response) bool `json:"-"`
	Backoff     func(retries uint) time.Duration `json:"-"`
}

type Settings

type Settings struct {
	RetrySettings   RetrySettings   `json:"retrySettings"`
	BreakerSettings BreakerSettings `json:"breakerSettings"`
}

func NewHttpSettings

func NewHttpSettings(settings *Settings) *Settings

Jump to

Keyboard shortcuts

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