gohttp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMock

func AddMock(mock Mock)

func FlushMocks

func FlushMocks()

func StartMockServer

func StartMockServer()

func StopMockServer

func StopMockServer()

Types

type Client

type Client 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)
}

type ClientBuilder

type ClientBuilder interface {
	SetHeader(headers http.Header) ClientBuilder
	SetConnectionTimeout(timeout time.Duration) ClientBuilder
	SetMaxIdleConnections(conn int) ClientBuilder
	SetRequestTimeout(timeout time.Duration) ClientBuilder
	DisableTimeouts(b bool) ClientBuilder
	SetHttpClient(c *http.Client) ClientBuilder
	SetUserAgent(userAgent string) ClientBuilder

	Build() Client
}

func NewBuilder

func NewBuilder() ClientBuilder

type Mock

type Mock struct {
	Method      string
	Url         string
	RequestBody string

	ResponseBody       string
	ResponseStatusCode int
	Error              error
}

Mock struct configure HTTP mocks based on the combination between request method, request url and request body.

func (*Mock) GetResponse

func (m *Mock) GetResponse() (*Response, error)

GetResponse returns an response object based on the mock configuration.

type Response

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

func (*Response) Bytes

func (r *Response) Bytes() []byte

func (*Response) Headers

func (r *Response) Headers() http.Header

func (*Response) Status

func (r *Response) Status() string

func (*Response) StatusCode

func (r *Response) StatusCode() int

func (*Response) String

func (r *Response) String() string

func (*Response) UnmarshalJson

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

Jump to

Keyboard shortcuts

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