httpgo

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientBuilder

type ClientBuilder interface {
	SetCommonHeaders(headers http.Header) ClientBuilder
	SetConnectionTimeout(timeout time.Duration) ClientBuilder
	SetResponseTimeout(timeout time.Duration) ClientBuilder
	SetMaxIdleConnections(connections int) ClientBuilder
	SetHttpClient(client *http.Client) ClientBuilder
	SetUserAgent(agent string) ClientBuilder
	DisableAllTimeouts(disable bool) ClientBuilder
	Build() HttpClient

	BuildMockClient() (HttpClient, MockKeeper)
}

ClientBuilder provides a clean way to configure HTTP Client based on the combination of methods

func NewBuilder

func NewBuilder() ClientBuilder

type HttpClient

type HttpClient interface {
	Get(url string, headers ...http.Header) (*Response, error)
	Post(url string, body interface{}, headers ...http.Header) (*Response, error)
	Put(url string, body interface{}, headers ...http.Header) (*Response, error)
	Patch(url string, body interface{}, headers ...http.Header) (*Response, error)
	Delete(url string, headers ...http.Header) (*Response, error)
	Options(url string, headers ...http.Header) (*Response, error)
}

HttpClient provides a clean way to perform an HTTP call

type Mock

type Mock struct {
	Method      string
	Url         string
	RequestBody string

	Error              error
	ResponseStatusCode int
	ResponseBody       string
	ResponseHeaders    http.Header
}

Mock structure provides a clean way to configure HTTP mocks based on the combination between HTTP method, URL and HTTP body (md5 hash).

type MockKeeper

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

func (*MockKeeper) AddMock

func (m *MockKeeper) AddMock(mock Mock)

func (*MockKeeper) DeleteMocks

func (m *MockKeeper) DeleteMocks()

type Response

type Response struct {
	Status     string
	StatusCode int
	Headers    http.Header
	Body       []byte
}

func (*Response) String

func (r *Response) String() string

func (*Response) UnmarshalJSON

func (r *Response) UnmarshalJSON(target interface{}) error

func (*Response) UnmarshalXML

func (r *Response) UnmarshalXML(target interface{}) error

Jump to

Keyboard shortcuts

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