interceptor

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CircuteBreakerForJust429 = gobreaker.NewCircuitBreaker(gobreaker.Settings{
	Name:        "circuteBreakerForJust429",
	MaxRequests: 0,
	Interval:    10 * time.Second,
	Timeout:     20 * time.Second,
	ReadyToTrip: func(counts gobreaker.Counts) bool {
		return counts.ConsecutiveFailures > 0
	},
	IsSuccessful: func(err error) bool {
		return err.Error() != "429"
	},
})

Functions

This section is empty.

Types

type BackoffStrategyExpnential

type BackoffStrategyExpnential struct {
	// contains filtered or unexported fields
}

func NewRetryInterceptor_BackoffStrategyLinier

func NewRetryInterceptor_BackoffStrategyLinier(baseDuration time.Duration) BackoffStrategyExpnential

func NewRetryInterceptor_ExponentialBackoff

func NewRetryInterceptor_ExponentialBackoff(baseDuration, maxBackoff time.Duration) BackoffStrategyExpnential

func (BackoffStrategyExpnential) TimeToWait

func (b BackoffStrategyExpnential) TimeToWait(iteration int) time.Duration

type BackoffStrategyLinier

type BackoffStrategyLinier struct {
	// contains filtered or unexported fields
}

func (BackoffStrategyLinier) TimeToWait

func (b BackoffStrategyLinier) TimeToWait(iteration int) time.Duration

type BackoffTimer

type BackoffTimer interface {
	TimeToWait(iteration int) time.Duration
}

type CircuitBreakerInterceptor

type CircuitBreakerInterceptor struct {
	// contains filtered or unexported fields
}

func NewCircuitBreakerInterceptor

func NewCircuitBreakerInterceptor(cb *gobreaker.CircuitBreaker, abortOnFailure bool) *CircuitBreakerInterceptor

NewCircuitBreakerInterceptor creates a new circuit breaker interceptor faced status codes (including 2xx) are passed as simple string to ReadyToTrip function.

func (*CircuitBreakerInterceptor) AfterResponse

AfterResponse records failures in the circuit breaker

func (*CircuitBreakerInterceptor) BeforeRequest

BeforeRequest checks if the circuit breaker is open

type ClientHandler

type ClientHandler interface {
	ProcessRequest(httpRequest *http.Request, successCode int, id string) (*http.Response, error)
}

type ClientInterceptor

type ClientInterceptor interface {
	// BeforeRequest is called before executing an HTTP request
	// It can modify the request or perform pre-request actions
	//
	// NOTE: moidfiying InterceptorData.Response at this step will prevent calling AfterResponse
	//  and directly returns this response as response of server
	BeforeRequest(InterceptorData) InterceptorData

	// AfterResponse is called after receiving an HTTP response
	// It can modify the response or perform post-response actions
	AfterResponse(InterceptorData) InterceptorData
}

type InterceptorData

type InterceptorData struct {
	ID             string // this ID will remain the same among all interceptors of an iteration
	InitialRequest *http.Request
	Request        *http.Request
	Response       *http.Response
	Context        context.Context
	Error          error
}

type RetryDecider

type RetryDecider interface {
	// ShouldRetry determines whether a failed HTTP request should be retried.
	// It receives the HTTP response (if any), the error (if any), and retry metadata.
	// Returns:
	//   - bool: true if the request should be retried, false otherwise
	//   - error: non-nil if an error occurred during the decision process. returning error stops the whole interceptorsChain.
	ShouldRetry(*http.Response, error, RetryInternalData) (bool, error)
}

type RetryDeciderAll

type RetryDeciderAll struct {
	// contains filtered or unexported fields
}

func NewRetryInterceptor_RetryDeciderAll

func NewRetryInterceptor_RetryDeciderAll(maxRetries int) RetryDeciderAll

func (RetryDeciderAll) ShouldRetry

func (r RetryDeciderAll) ShouldRetry(response *http.Response, err error, retryData RetryInternalData) (bool, error)

type RetryInterceptor

type RetryInterceptor struct {
	// contains filtered or unexported fields
}

func NewRetryInterceptor

func NewRetryInterceptor(clientHandler ClientHandler, backoffStrategy BackoffTimer, retryDecider RetryDecider) *RetryInterceptor

func (*RetryInterceptor) AfterResponse

func (e *RetryInterceptor) AfterResponse(data InterceptorData) InterceptorData

func (*RetryInterceptor) BeforeRequest

func (e *RetryInterceptor) BeforeRequest(data InterceptorData) InterceptorData

type RetryInternalData

type RetryInternalData struct {
	RetryCount int
}

Jump to

Keyboard shortcuts

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