client

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidHeader is returned when there is an error while parsing the header line.
	ErrInvalidHeader = errors.New("invalid header line")
	// ErrInvalidProtocol is returned when there is an error while parsing the protocol.
	ErrInvalidProtocol = errors.New("invalid protocol")
	// ErrInvalidStatusCode is returned when there is an error while parsing the status code.
	ErrInvalidStatusCode = errors.New("invalid status code")
	// ErrInvalidStatusLine is returned when there is an error while parsing the status line.
	ErrInvalidStatusLine = errors.New("invalid status line")
	// ErrInvalidGZIP is returned when there is an error while reading a gzipped response body.
	ErrInvalidGZIP = errors.New("invalid gzip encoding")
)

Functions

func NewPool

func NewPool(ctx context.Context, size uint32, opts ...Opt) func() (*Pooled, error)

NewPool is a constructor function that creates a new collection of Pooled clients, on top of a new Client with the given Opt.

The pool is a buffered channel that can hold up to [size] clients. If the pool is full, it will wait until a client is available. Use it to limit the number of clients that can be created, and thus the total amount of ongoing requests and open connections.

Take a look at [pool_test.go] for usage examples.

Types

type Client

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

Client is a custom implementation of an HTTP client that can be used to perform HTTP requests.

func New

func New(opts ...Opt) *Client

New is a constructor function that creates a new instance of the Client type with the given options Opt.

func (*Client) Do

Do perform an HTTP request with the given request.Request and returns a response.Response and an error, if any.

type NetError

type NetError string

NetError represents a network error.

func (*NetError) Error

func (err *NetError) Error() string

Error returns the error message. Implements the [error] interface.

func (*NetError) GobDecode

func (err *NetError) GobDecode(b []byte) error

GobDecode decodes the error from a byte slice. Implements the gob.GobDecoder interface.

func (*NetError) GobEncode

func (err *NetError) GobEncode() ([]byte, error)

GobEncode encodes the error into a byte slice. Implements the gob.GobEncoder interface.

type Opt

type Opt func(*Client)

Opt is a functional option for the Client.

func WithProxyAddr

func WithProxyAddr(addr string) Opt

WithProxyAddr is an option that sets the proxy address.

func WithProxyAuth

func WithProxyAuth(auth string) Opt

WithProxyAuth is an option that sets the proxy authentication.

type Pooled

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

func NewPooled

func NewPooled(pool chan *Pooled, opts ...Opt) *Pooled

func (*Pooled) Do

Jump to

Keyboard shortcuts

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