httpclient

package
v0.0.0-...-11d5444 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.Mutex
	*http.Client
	// contains filtered or unexported fields
}

Client special http client that can throttle requests per seconds (RPS). Also collect stats about current RPS and overall bytes downloaded/uploaded.

func NewClient

func NewClient() *Client

NewClient ...

func (*Client) BytesDownloaded

func (c *Client) BytesDownloaded() int64

func (*Client) BytesUploaded

func (c *Client) BytesUploaded() int64

func (*Client) Do

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

Do executes a request

func (*Client) FakeDo

func (c *Client) FakeDo()

FakeDo for testing purposes

func (*Client) Get

func (c *Client) Get(url string) (*http.Response, error)

func (*Client) GetRPS

func (c *Client) GetRPS() int32

GetRPS gets the current client RPS

func (*Client) Post

func (c *Client) Post(url, contentType string, body io.Reader) (resp *http.Response, err error)

func (*Client) PostForm

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

func (*Client) SetMaxRPS

func (c *Client) SetMaxRPS(maxRPS int32)

SetMaxRPS ...

func (*Client) SetTransport

func (c *Client) SetTransport(tr http.RoundTripper)

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(userAgent string)

func (*Client) UserAgent

func (c *Client) UserAgent() string

func (*Client) WithTransport

func (c *Client) WithTransport(tr http.RoundTripper, clb func(*Client) error) error

type IHttpClient

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

Jump to

Keyboard shortcuts

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