httpclient

package
v0.0.0-...-6067ee5 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cli

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

Cli is a HTTP client

func New

func New(name string, dumpDir, ua, prxURL string, dump bool, log *logger.Logger) (*Cli, error)

New instantiates a client

func (*Cli) Client

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

Client returns underlying http client

func (*Cli) DoRequest

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

DoRequest performs an HTTP request

func (*Cli) DumpTransaction

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

DumpTransaction dumps an HTTP transaction content into a file

func (*Cli) Get

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

Get perform a GET request

func (*Cli) GetExtIPAddrInfo

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

GetExtIPAddrInfo returns information about client's external IP address

func (*Cli) GetFile

func (c *Cli) 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 (*Cli) GetJSON

func (c *Cli) 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 (*Cli) GetQueryDoc

func (c *Cli) 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 (*Cli) Post

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

Post performs a POST request

func (*Cli) PostForm

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

PostForm posts a form

func (*Cli) PostFormParseJSON

func (c *Cli) 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 (*Cli) PostJSON

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

PostJSON posts a JSON request

func (*Cli) PostJSONParseJSON

func (c *Cli) 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 (*Cli) Reset

func (c *Cli) Reset() error

Reset resets the client

func (*Cli) SetErrorHandler

func (c *Cli) SetErrorHandler(fn ErrorHandler)

SetErrorHandler sets HTTP request error handler

type ErrorHandler

type ErrorHandler func(ctx context.Context, c *Cli, req *http.Request, rsp *http.Response, err error, tryN int) error

ErrorHandler is HTTP request error handler

Jump to

Keyboard shortcuts

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