http

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalStub func(*http.Request) *http.Response

GlobalStub is test double and it is used when we cannot or don’t want to involve real server. Instead of the real server, we introduced a stub and defined what data should be returned. Example:

func(request *http.Request) *http.Response {
	resp := &http.Response{}
	if request.URL.String() == "127.0.0.1" {
		resp.StatusCode = http.StatusOK
		resp.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
	}
	return resp
}

Functions

This section is empty.

Types

type Client added in v0.0.5

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

func NewClient added in v0.0.5

func NewClient(options ...Option) *Client

func (*Client) CloseIdleConnections added in v0.0.5

func (c *Client) CloseIdleConnections(ctx context.Context)

func (*Client) Do added in v0.0.5

func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response,
	error)

func (*Client) Get added in v0.0.5

func (c *Client) Get(ctx context.Context, addr string) (resp *http.Response,
	err error)

func (*Client) Head added in v0.0.5

func (c *Client) Head(ctx context.Context, addr string) (resp *http.Response,
	err error)

func (*Client) Post added in v0.0.5

func (c *Client) Post(ctx context.Context, addr, contentType string,
	body io.Reader) (resp *http.Response, err error)

func (*Client) PostForm added in v0.0.5

func (c *Client) PostForm(ctx context.Context, addr string,
	data url.Values) (resp *http.Response, err error)

type ClientOptions

type ClientOptions struct{}

func (ClientOptions) WithLogger

func (ClientOptions) WithLogger(logger log.Logger) Option

func (ClientOptions) WithProxy

func (ClientOptions) WithProxy(proxys ...func() interface{}) Option

func (ClientOptions) WithTimeOut

func (ClientOptions) WithTimeOut(timeout time.Duration) Option

type MonitorProxy added in v0.0.9

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

MonitorProxy wraps a RoundTripper.

func NewMonitorProxy

func NewMonitorProxy(options ...MonitorProxyOption) *MonitorProxy

func (*MonitorProxy) NextProxy added in v0.0.9

func (mp *MonitorProxy) NextProxy(tripper interface{})

func (*MonitorProxy) ProxyName added in v0.0.9

func (mp *MonitorProxy) ProxyName() string

func (*MonitorProxy) RoundTrip added in v0.0.9

func (mp *MonitorProxy) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type MonitorProxyOption

type MonitorProxyOption func(c *MonitorProxy)

type MonitorProxyOptions

type MonitorProxyOptions struct{}

func (MonitorProxyOptions) WithConf

func (MonitorProxyOptions) WithLogger

func (MonitorProxyOptions) WithLogger(logger log.Logger) MonitorProxyOption

func (MonitorProxyOptions) WithTracer

Use nethttp.Tracer.

type Option

type Option func(c *Client)

type RespFunc added in v0.0.9

type RespFunc func(*http.Request) *http.Response

type StubsProxy added in v0.1.2

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

func NewStubsProxy

func NewStubsProxy(options ...StubsProxyOption) *StubsProxy

func (*StubsProxy) NextProxy added in v0.1.2

func (sp *StubsProxy) NextProxy(tripper interface{})

func (*StubsProxy) ProxyName added in v0.1.2

func (sp *StubsProxy) ProxyName() string

func (*StubsProxy) RoundTrip added in v0.1.2

func (sp *StubsProxy) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type StubsProxyOption

type StubsProxyOption func(c *StubsProxy)

type StubsProxyOptions

type StubsProxyOptions struct{}

func (StubsProxyOptions) WithLogger

func (StubsProxyOptions) WithLogger(logger log.Logger) StubsProxyOption

func (StubsProxyOptions) WithName

func (StubsProxyOptions) WithName(name string) StubsProxyOption

func (StubsProxyOptions) WithRespFunc

func (StubsProxyOptions) WithRespFunc(respFunc RespFunc) StubsProxyOption

Jump to

Keyboard shortcuts

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