http

package
v0.0.0-...-ac81adf Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Breaker

type Breaker interface {
	// Execute runs the given request if the circuit breaker is closed or half-open states.
	// An error is instantly returned when the circuit breaker is tripped.
	Execute(func() (interface{}, error)) (interface{}, error)
}

Breaker is the http circuit breaker.

type CircuitBreaker

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

CircuitBreaker is the application http transport.

func NewCircuitBreaker

func NewCircuitBreaker(cb Breaker) *CircuitBreaker

NewCircuitBreaker returns a new configured CircuitBreaker with circuit breaker.

func (*CircuitBreaker) RoundTrip

func (t *CircuitBreaker) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip decorates rt.RoundTrip with a circuit breaker. An error is returned if the circuit breaker rejects the request.

type Client

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

Client is the http wrapper for the application

func NewClient

func NewClient(r *Request) *Client

NewClient returns a configured Client

func (*Client) Get

func (c *Client) Get(url string) (*http.Response, error)

Get executes a GET http request

type Func

type Func func() error

Func is the function to be executed and eventually retried.

type Request

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

Request is the application http request.

func NewRequest

func NewRequest(opts ...RequestOption) *Request

NewRequest returns a new configured Request.

func (*Request) Do

func (r *Request) Do(method, url, contentType string, body io.Reader) (*http.Response, error)

Do is a convenient method for executing http requests.

type RequestOption

type RequestOption func(*Request)

RequestOption is the request options.

func WithCircuitBreaker

func WithCircuitBreaker(rt http.RoundTripper) RequestOption

WithCircuitBreaker receives the http.RoundTripper implementation.

func WithRetry

func WithRetry(rt http.RoundTripper) RequestOption

WithRetry receives the http.RoundTripper implementation.

func WithTimeout

func WithTimeout(t time.Duration) RequestOption

type Retry

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

Retry is mechanism the application retry.

func NewRetry

func NewRetry(attempts int, statusCode []int, sleep time.Duration) *Retry

NewRetry returns a new configured CircuitBreaker with retry.

func (*Retry) RoundTrip

func (r *Retry) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip decorates RoundTrip with a retry.

Jump to

Keyboard shortcuts

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