httpclient

package module
v0.0.0-...-9f1a579 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: MIT Imports: 10 Imported by: 0

README

httpclient

CI

Golang http client adapter for production usage.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecorateDoerTransport

func DecorateDoerTransport(c *http.Client, ds ...TransportDecoratorFunc) *http.Client

DecorateDoerTransport decorates internal Transport of http.Client

func DecorateDoerTransportByDefault

func DecorateDoerTransportByDefault(c *http.Client) *http.Client

DecorateDoerTransportByDefault decorates a http.Client c with default set of decorators: 1. Error

func DecorateTransport

func DecorateTransport(rt http.RoundTripper, ds ...TransportDecoratorFunc) http.RoundTripper

DecorateTransport decorates a http.RoundTripper c with all the given Decorators, in order.

func DefaultDoer

func DefaultDoer() *http.Client

DefaultDoer returns a new http.Client with similar default values to http.Client, but with a non-shared Transport. Intended to be reused for requests to the same host.

func DefaultTransport

func DefaultTransport() *http.Transport

DefaultTransport returns a new http.Transport with similar default values to http.DefaultTransport. Intended to be reused for requests to the same host.

Types

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer is an interface supported by http.Client. Use this interface whenever you need to abstract from http.Client implementation and to use decorated client.

func DecorateDoer

func DecorateDoer(c Doer, ds ...DoerDecoratorFunc) Doer

DecorateDoer decorates a Doer c with all the given Decorators, in order.

func DecorateDoerByDefault

func DecorateDoerByDefault(c Doer, serviceName string) Doer

DecorateDoerByDefault decorates a Doer c with default set of decorators: 1. Error

type DoerDecoratorFunc

type DoerDecoratorFunc func(Doer) Doer

DoerDecoratorFunc wraps a Doer with extra behaviour.

func ErrorDoerDecorator

func ErrorDoerDecorator(serviceName string) DoerDecoratorFunc

ErrorDoerDecorator is a Doer decorator which wraps raised error with service name context.

type DoerFunc

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

DoerFunc is a function type that implements the Doer interface.

func (DoerFunc) Do

func (f DoerFunc) Do(r *http.Request) (*http.Response, error)

Do supports Doer interface

type DoerMock

type DoerMock struct {
	DoMock mDoerMockDo
	// contains filtered or unexported fields
}

DoerMock implements Doer

func NewDoerMock

func NewDoerMock(t minimock.Tester) *DoerMock

NewDoerMock returns a mock for Doer

func (*DoerMock) Do

func (mmDo *DoerMock) Do(req *http.Request) (rp1 *http.Response, err error)

Do implements Doer

func (*DoerMock) DoAfterCounter

func (mmDo *DoerMock) DoAfterCounter() uint64

DoAfterCounter returns a count of finished DoerMock.Do invocations

func (*DoerMock) DoBeforeCounter

func (mmDo *DoerMock) DoBeforeCounter() uint64

DoBeforeCounter returns a count of DoerMock.Do invocations

func (*DoerMock) MinimockDoDone

func (m *DoerMock) MinimockDoDone() bool

MinimockDoDone returns true if the count of the Do invocations corresponds the number of defined expectations

func (*DoerMock) MinimockDoInspect

func (m *DoerMock) MinimockDoInspect()

MinimockDoInspect logs each unmet expectation

func (*DoerMock) MinimockFinish

func (m *DoerMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*DoerMock) MinimockWait

func (m *DoerMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

type DoerMockDoExpectation

type DoerMockDoExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

DoerMockDoExpectation specifies expectation struct of the Doer.Do

func (*DoerMockDoExpectation) Then

func (e *DoerMockDoExpectation) Then(rp1 *http.Response, err error) *DoerMock

Then sets up Doer.Do return parameters for the expectation previously defined by the When method

type DoerMockDoParams

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

DoerMockDoParams contains parameters of the Doer.Do

type DoerMockDoResults

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

DoerMockDoResults contains results of the Doer.Do

type DumpRequestFunc

type DumpRequestFunc func(r *http.Request, body bool) ([]byte, error)

DumpRequestFunc function to dump request. In most cases httputil.DumpRequestOut can be used

type DumpResponseFunc

type DumpResponseFunc func(r *http.Response, body bool) ([]byte, error)

DumpResponseFunc function to dump response. In most cases httputil.DumpResponse can be used

type LoggerFromRequestFunc

type LoggerFromRequestFunc func(r *http.Request) log.Logger

LoggerFromRequestFunc is a function to get logger from request/to enrich logger with context meta data.

type TransportDecoratorFunc

type TransportDecoratorFunc func(http.RoundTripper) http.RoundTripper

TransportDecoratorFunc wraps a http.RoundTripper with extra behaviour.

func ErrorTransportDecorator

func ErrorTransportDecorator() TransportDecoratorFunc

ErrorDoerDecorator is a net/http.Transport decorator which wraps raised error with requested host context.

func LoggerTransportDecorator

func LoggerTransportDecorator(loggerFromRequestFn LoggerFromRequestFunc) TransportDecoratorFunc

LoggerTransportDecorator creates

func LoggerTransportDecoratorWithDumpers

func LoggerTransportDecoratorWithDumpers(
	reqFn DumpRequestFunc,
	respFn DumpResponseFunc,
	loggerFromRequestFn LoggerFromRequestFunc,
) TransportDecoratorFunc

LoggerTransportDecoratorWithDumpers is a net/http.Transport decorator which logs response body to context`s logger

type TransportFunc

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

TransportFunc is a function type that implements the http.RoundTripper interface.

func (TransportFunc) RoundTrip

func (f TransportFunc) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip supports http.RoundTripper interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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