Documentation ¶
Overview ¶
Package httpclient is a generated GoMock package.
Index ¶
- Constants
- type BackOff
- type CheckRetry
- type Client
- type Doer
- type ErrorHandler
- type ErrorHook
- type HttpClient
- func (c *HttpClient) Delete(ctx context.Context, url string, headers http.Header) (*http.Response, error)
- func (c *HttpClient) Do(req *http.Request) (resp *http.Response, err error)
- func (c *HttpClient) Get(ctx context.Context, url string, headers http.Header) (*http.Response, error)
- func (c *HttpClient) Post(ctx context.Context, url string, body io.Reader, headers http.Header) (*http.Response, error)
- func (c *HttpClient) Put(ctx context.Context, url string, body io.Reader, headers http.Header) (*http.Response, error)
- type MockDoer
- type MockDoerMockRecorder
- type Option
- func WithBackOff(b BackOff) Option
- func WithBaseURL(u string) Option
- func WithCheckRetry(cr CheckRetry) Option
- func WithDoer(client Doer) Option
- func WithErrorHandler(eh ErrorHandler) Option
- func WithErrorHook(eh ErrorHook) Option
- func WithRequestHook(rh RequestHook) Option
- func WithResponseHook(rh ResponseHook) Option
- func WithRetryCount(retryCount int) Option
- func WithTimeout(timeout time.Duration) Option
- type RequestHook
- type ResponseHook
Constants ¶
const (
DefaultHTTPTimeout = 60 * time.Second
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackOff ¶
BackOff specifies a policy for how long to wait between retries. It is called after a failing request to determine the amount of time that should pass before trying again.
type CheckRetry ¶
CheckRetry specifies a policy for handling retries. It is called following each request with the response and error values returned by the http.Client. If CheckRetry returns false, the Client stops retrying and returns the response to the caller. If CheckRetry returns an error, that error value is returned in lieu of the error from the request. The Client will close any response body when retrying, but if the retry is aborted it is up to the CheckRetry callback to properly close any response body before returning.
type Client ¶
type Client interface { Get(ctx context.Context, url string, headers http.Header) (*http.Response, error) Post(ctx context.Context, url string, body io.Reader, headers http.Header) (*http.Response, error) Put(ctx context.Context, url string, body io.Reader, headers http.Header) (*http.Response, error) Delete(ctx context.Context, url string, headers http.Header) (*http.Response, error) Do(req *http.Request) (*http.Response, error) }
Client is a generic HTTP client interface.
type Doer ¶
Doer interface has the method required to use a type as custom http client. The net/*http.Client type satisfies this interface.
type ErrorHandler ¶
ErrorHandler is called if retries are expired, containing the last status from the http library. If not specified, default behavior for the library is to close the body and return an error indicating how many tries were attempted. If overriding this, be sure to close the body if needed.
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
HttpClient is the http client implementation
func (*HttpClient) Delete ¶
func (c *HttpClient) Delete(ctx context.Context, url string, headers http.Header) (*http.Response, error)
Delete makes a HTTP DELETE request with provided URL.
func (*HttpClient) Get ¶
func (c *HttpClient) Get(ctx context.Context, url string, headers http.Header) (*http.Response, error)
Get makes a HTTP GET request to provided URL.
type MockDoer ¶
type MockDoer struct {
// contains filtered or unexported fields
}
MockDoer is a mock of Doer interface
func NewMockDoer ¶
func NewMockDoer(ctrl *gomock.Controller) *MockDoer
NewMockDoer creates a new mock instance
func (*MockDoer) EXPECT ¶
func (m *MockDoer) EXPECT() *MockDoerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
type MockDoerMockRecorder ¶
type MockDoerMockRecorder struct {
// contains filtered or unexported fields
}
MockDoerMockRecorder is the mock recorder for MockDoer
func (*MockDoerMockRecorder) Do ¶
func (mr *MockDoerMockRecorder) Do(arg0 interface{}) *gomock.Call
Do indicates an expected call of Do
type Option ¶
type Option func(client *HttpClient)
func WithBackOff ¶
func WithBaseURL ¶
func WithCheckRetry ¶
func WithCheckRetry(cr CheckRetry) Option
func WithErrorHandler ¶
func WithErrorHandler(eh ErrorHandler) Option
func WithErrorHook ¶
func WithRequestHook ¶
func WithRequestHook(rh RequestHook) Option
func WithResponseHook ¶
func WithResponseHook(rh ResponseHook) Option
func WithRetryCount ¶
func WithTimeout ¶
type RequestHook ¶
RequestHook allows a function to run before each retry. The HTTP request which will be made, and the retry number (0 for the initial request) are available to users.
type ResponseHook ¶
ResponseHook is like RequestHook, but allows running a function on each HTTP response. This function will be invoked at the end of every HTTP request executed, regardless of whether a subsequent retry needs to be performed or not. If the response body is read or closed from this method, this will affect the response returned from Do().