httputil

package
v5.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package httputil implements utility for httpClient with request retry and optional tracing

Index

Constants

This section is empty.

Variables

View Source
var ErrResponseFromUpstream = fmt.Errorf("HttpClient.Call: non 2xx status")
View Source
var ErrResponseUnmarshal = fmt.Errorf("error marshalling response body")

Functions

This section is empty.

Types

type Backoff

type Backoff func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration

type CheckRetry

type CheckRetry func(ctx context.Context, resp *http.Response, err error) (bool, error)

type HTTPClient

type HTTPClient struct {
	*http.Client
	// contains filtered or unexported fields
}

func New

func New(log log.Log, tr Tracer, c *http.Client, retryMax int, retryWaitMin, retryWaitMax time.Duration) *HTTPClient

New creates a new HTTPClient wrapper for passed *http.Client

func NewDefaultHTTPClient

func NewDefaultHTTPClient(log log.Log, t Tracer) *HTTPClient

NewDefaultHTTPClient creates a new HTTPClient with default options

func NewH2CClient

func NewH2CClient(log log.Log, tr Tracer, retryMax int, retryWaitMin, retryWaitMax time.Duration) *HTTPClient

NewH2CClient creates a new HTTPClient with configuration to support h2c servers

func NewHTTPClient

func NewHTTPClient(log log.Log, tr Tracer, retryMax int, retryWaitMin, retryWaitMax time.Duration) *HTTPClient

NewHTTPClient creates a new HTTPClient

func (*HTTPClient) Call

func (h *HTTPClient) Call(ctx context.Context, method, url string, reqBody, resBody interface{}, headers map[string]string) (*http.Response, error)

Call pre-processes the request and response

func (*HTTPClient) Decode

func (h *HTTPClient) Decode(ctx context.Context, body []byte, data interface{}) (io.ReadCloser, error)

Decode un-marshals the passed bytes to an object and returns a copy in io.ReadCloser

func (*HTTPClient) Delete

func (h *HTTPClient) Delete(ctx context.Context, url string, reqBody, resBody interface{}, headers map[string]string) (*http.Response, error)

Delete HTTP DELETE method invocation

func (*HTTPClient) Do

func (h *HTTPClient) Do(req *http.Request) (*http.Response, error)

Do adds additional retry and backoff mechanism

func (*HTTPClient) Encode

func (h *HTTPClient) Encode(ctx context.Context, data interface{}) (io.Reader, error)

Encode marshals the passed object and creates the io.Reader object

func (*HTTPClient) Get

func (h *HTTPClient) Get(ctx context.Context, url string, reqBody, resBody interface{}, headers map[string]string) (*http.Response, error)

Get HTTP GET method invocation

func (*HTTPClient) Patch

func (h *HTTPClient) Patch(ctx context.Context, url string, reqBody, resBody interface{}, headers map[string]string) (*http.Response, error)

Patch HTTP PATCH method invocation

func (*HTTPClient) Post

func (h *HTTPClient) Post(ctx context.Context, url string, reqBody, resBody interface{}, headers map[string]string) (*http.Response, error)

Post HTTP POST method invocation

func (*HTTPClient) Put

func (h *HTTPClient) Put(ctx context.Context, url string, reqBody, resBody interface{}, headers map[string]string) (*http.Response, error)

Put HTTP PUT method invocation

type Tracer

type Tracer interface {
	HTTPWrapTransport(http.RoundTripper) http.RoundTripper
	HTTPRequestTrace(context.Context) *httptrace.ClientTrace
	span.SpanOp
}

Jump to

Keyboard shortcuts

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