rest

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff interface {
	Next(retry int) time.Duration
}

Backoff interface defines contract for backoff strategies

func NewConstantBackoff

func NewConstantBackoff(backoffInterval, maximumJitterInterval time.Duration) Backoff

NewConstantBackoff returns an instance of ConstantBackoff

func NewExponentialBackoff

func NewExponentialBackoff(initialTimeout, maxTimeout time.Duration, exponentFactor float64, maximumJitterInterval time.Duration) Backoff

NewExponentialBackoff returns an instance of ExponentialBackoff

type Client

type Client interface {
	Get(url string, headers http.Header) (*http.Response, error)
	Post(url string, body io.Reader, headers http.Header) (*http.Response, error)
	Put(url string, body io.Reader, headers http.Header) (*http.Response, error)
	Patch(url string, body io.Reader, headers http.Header) (*http.Response, error)
	Delete(url string, headers http.Header) (*http.Response, error)
	Do(req *http.Request) (*http.Response, error)
	Options() Options
}

Client http client interface

func New

func New(opts ...Option) Client

New returns a new instance of http client

type DoFunc

type DoFunc func(*http.Request, func(*http.Response) error) error

DoFunc http client do func wrapper

type Middleware

type Middleware func(DoFunc) DoFunc

Middleware http client middleware

type Option

type Option func(opts *Options)

Option ...

func WithHTTPTimeout

func WithHTTPTimeout(timeout time.Duration) Option

WithHTTPTimeout sets hystrix timeout

func WithMiddleware

func WithMiddleware(m Middleware) Option

WithMiddleware sets the strategy for retrying

func WithRetrier

func WithRetrier(retrier Retriable) Option

WithRetrier sets the strategy for retrying

func WithRetryCount

func WithRetryCount(retryCount int) Option

WithRetryCount sets the retry count for the client

type Options

type Options struct {
	Retrier    Retriable
	Timeout    time.Duration
	RetryCount int
	Middles    []Middleware
}

Options represents the http client options

type Retriable

type Retriable interface {
	NextInterval(retry int) time.Duration
}

Retriable defines contract for retriers to implement

func NewNoRetrier

func NewNoRetrier() Retriable

NewNoRetrier returns a null object for retriable

func NewRetrier

func NewRetrier(backoff Backoff) Retriable

NewRetrier returns retrier with some backoff strategy

func NewRetrierFunc

func NewRetrierFunc(f RetriableFunc) Retriable

NewRetrierFunc returns a retrier with a retry function defined

type RetriableFunc

type RetriableFunc func(retry int) time.Duration

RetriableFunc is an adapter to allow the use of ordinary functions as a Retriable

func (RetriableFunc) NextInterval

func (f RetriableFunc) NextInterval(retry int) time.Duration

NextInterval calls f(retry)

Directories

Path Synopsis
httpclient

Jump to

Keyboard shortcuts

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