httpclient

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2017 License: MIT Imports: 6 Imported by: 0

README

Build Status Coverage Status Go Report Card

Description

The httpclient package provides an interface for Go's standard http.Client concrete type. This makes it easier to mock HTTP clients, or wrap them with additional functionality.

Usage

client := httpclient.NewContext(http.DefaultClient)
response, err := client.GetContext(ctx.TODO(), "https://golang.org")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
	Get(url string) (resp *http.Response, err error)
	Head(url string) (resp *http.Response, err error)
	Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)
	PostForm(url string, data url.Values) (resp *http.Response, err error)
}

Client provides an interface for the `http.Client` concrete type

type ClientContext

type ClientContext interface {
	Client
	// GetContext is the same as Get but accepts a context
	GetContext(ctx context.Context, url string) (resp *http.Response, err error)
	// HeadContext is the same as Head but accepts a context
	HeadContext(ctx context.Context, url string) (resp *http.Response, err error)
	// PostContext is the same as Post but accepts a context
	PostContext(ctx context.Context, url string, contentType string, body io.Reader) (resp *http.Response, err error)
	// PostFormContext is the same as PostForm but accepts a context
	PostFormContext(ctx context.Context, url string, data url.Values) (resp *http.Response, err error)
}

ClientContext provides context aware methods for HTTP requests

func NewContext

func NewContext(client Client) ClientContext

NewContext wraps a Client with context aware methods

type MockClient

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

MockClient is a mock of Client interface

func NewMockClient

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance

func (*MockClient) Do

func (_m *MockClient) Do(req *http.Request) (*http.Response, error)

Do mocks base method

func (*MockClient) EXPECT

func (_m *MockClient) EXPECT() *MockClientMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockClient) Get

func (_m *MockClient) Get(url string) (*http.Response, error)

Get mocks base method

func (*MockClient) Head

func (_m *MockClient) Head(url string) (*http.Response, error)

Head mocks base method

func (*MockClient) Post

func (_m *MockClient) Post(url string, contentType string, body io.Reader) (*http.Response, error)

Post mocks base method

func (*MockClient) PostForm

func (_m *MockClient) PostForm(url string, data url.Values) (*http.Response, error)

PostForm mocks base method

type MockClientMockRecorder

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

MockClientMockRecorder is the mock recorder for MockClient

func (*MockClientMockRecorder) Do

func (_mr *MockClientMockRecorder) Do(arg0 interface{}) *gomock.Call

Do indicates an expected call of Do

func (*MockClientMockRecorder) Get

func (_mr *MockClientMockRecorder) Get(arg0 interface{}) *gomock.Call

Get indicates an expected call of Get

func (*MockClientMockRecorder) Head

func (_mr *MockClientMockRecorder) Head(arg0 interface{}) *gomock.Call

Head indicates an expected call of Head

func (*MockClientMockRecorder) Post

func (_mr *MockClientMockRecorder) Post(arg0, arg1, arg2 interface{}) *gomock.Call

Post indicates an expected call of Post

func (*MockClientMockRecorder) PostForm

func (_mr *MockClientMockRecorder) PostForm(arg0, arg1 interface{}) *gomock.Call

PostForm indicates an expected call of PostForm

Jump to

Keyboard shortcuts

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