httpclient

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
	"(KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36"

Functions

func AddURLQueryArgs added in v0.0.12

func AddURLQueryArgs(a string, args url.Values) string

AddURLQueryArgs adds query arguments to a URL

Types

type Client

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

func New

func New(l zerolog.Logger) *Client

New instantiates a client

func (*Client) Client

func (c *Client) Client() *http.Client

func (*Client) DoRequest

func (c *Client) DoRequest(
	ctx context.Context,
	method,
	u string,
	header http.Header,
	body []byte,
) (*http.Response, []byte, error)

DoRequest performs an HTTP request

func (*Client) DumpTransaction

func (c *Client) DumpTransaction(
	req *http.Request,
	resp *http.Response,
	reqBody, respBody []byte,
	tryNum int,
)

DumpTransaction dumps an HTTP transaction content into a file

func (*Client) Get

func (c *Client) Get(ctx context.Context, u string, args url.Values, header http.Header) ([]byte, error)

Get perform a GET request

func (*Client) GetExtIPAddrInfo

func (c *Client) GetExtIPAddrInfo(ctx context.Context) (string, error)

GetExtIPAddrInfo returns information about client's external IP address

func (*Client) GetFile

func (c *Client) GetFile(ctx context.Context, u string, args url.Values, header http.Header, fPath string) (string, error)

GetFile gets a file and stores it on the disk.

If fPath doesn't contain an extension, it will be added automatically. In case of success file extension returned

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, u string, args url.Values, header http.Header, target interface{}) error

GetJSON performs a GET HTTP request and parses the response into a JSON

func (*Client) GetQueryDoc

func (c *Client) GetQueryDoc(ctx context.Context, u string, args url.Values, header http.Header) (*goquery.Document, error)

GetQueryDoc performs a GET request and transform response into a goquery document

func (*Client) Post

func (c *Client) Post(ctx context.Context, u string, header http.Header, body []byte) ([]byte, error)

Post performs a POST request

func (*Client) PostForm

func (c *Client) PostForm(ctx context.Context, u string, args url.Values, header http.Header) ([]byte, error)

PostForm posts a form

func (*Client) PostFormParseJSON

func (c *Client) PostFormParseJSON(ctx context.Context, u string, args url.Values, header http.Header, target interface{}) error

PostFormParseJSON performs a POST request and parses JSON response

func (*Client) PostJSON

func (c *Client) PostJSON(ctx context.Context, u string, header http.Header, data interface{}) ([]byte, error)

PostJSON posts a JSON request

func (*Client) PostJSONParseJSON

func (c *Client) PostJSONParseJSON(ctx context.Context, u string, data interface{}, header http.Header, target interface{}) error

PostJSONParseJSON performs a POST request having JSON body and parses JSON response

func (*Client) Reset

func (c *Client) Reset() error

func (*Client) SetDumpDir

func (c *Client) SetDumpDir(dir string) error

func (*Client) SetMaxTries

func (c *Client) SetMaxTries(n int)

func (*Client) SetProxyURLs

func (c *Client) SetProxyURLs(urls []string)

func (*Client) SetUserAgents

func (c *Client) SetUserAgents(ua []string)

Jump to

Keyboard shortcuts

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