http

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: Apache-2.0 Imports: 16 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error added in v1.13.0

func Error(span trace.Span, err error) bool

Types

type AuthConfig added in v1.13.0

type AuthConfig struct {
	// Username for basic Auth
	Username string

	// Password for basic Auth
	Password string

	// Ntlm controls whether to use NTLM
	Ntlm bool

	// Ntlmv2 controls whether to use NTLMv2
	Ntlmv2 bool
}

type Client

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

Client is a type that represents an HTTP client

func NewClient

func NewClient() *Client

NewClient configures a new HTTP client using given configuration

func (*Client) Auth added in v1.13.0

func (c *Client) Auth(username, password string) *Client

Auth sets up the username & password for basic auth or NTLM.

func (*Client) BaseURL added in v1.13.0

func (c *Client) BaseURL(url string) *Client

func (*Client) CacheDNS added in v1.13.0

func (c *Client) CacheDNS(val bool) *Client

func (*Client) ConnectTo added in v1.13.0

func (c *Client) ConnectTo(host string) *Client

ConnectTo specifies the host:port on which the URL is sought. If empty, the URL's host is used.

func (*Client) DisableKeepAlive added in v1.13.0

func (c *Client) DisableKeepAlive(val bool) *Client

DisableKeepAlives prevents reuse of TCP connections

func (*Client) Header added in v1.13.0

func (c *Client) Header(key, val string) *Client

func (*Client) InsecureSkipVerify added in v1.13.0

func (c *Client) InsecureSkipVerify(val bool) *Client

InsecureSkipVerify controls whether a client verifies the server's certificate chain and host name

func (*Client) NTLM added in v1.13.0

func (c *Client) NTLM(val bool) *Client

func (*Client) NTLMV2 added in v1.13.0

func (c *Client) NTLMV2(val bool) *Client

func (*Client) Proxy added in v1.13.0

func (c *Client) Proxy(url string) *Client

func (*Client) R added in v1.13.0

func (c *Client) R(ctx context.Context) *Request

R create a new request.

func (*Client) Retry added in v1.13.0

func (c *Client) Retry(maxRetries uint, baseDuration time.Duration, exponent float64) *Client

Retry configuration retrying on failure with exponential backoff.

Base duration of a second & an exponent of 2 is a good option.

func (*Client) Timeout added in v1.13.0

func (c *Client) Timeout(d time.Duration) *Client

Timeout specifies a time limit for requests made by this Client.

Default: 2 minutes

func (*Client) Use added in v1.13.0

func (c *Client) Use(middlewares ...Middleware) *Client

Use adds middleware to the client that wraps the client's transport

type Middleware added in v1.13.0

type Middleware func(http.RoundTripper) http.RoundTripper

type Request

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

func (*Request) Body added in v1.13.0

func (r *Request) Body(v any) error

Body sets the request body

func (*Request) Delete added in v1.13.0

func (r *Request) Delete(url string) (*Response, error)

func (*Request) Do added in v1.13.0

func (r *Request) Do(method, reqURL string) (resp *Response, err error)

Do performs an HTTP request with the specified method and URL.

func (*Request) Get added in v1.13.0

func (r *Request) Get(url string) (*Response, error)

func (*Request) Header added in v1.13.0

func (r *Request) Header(key, value string) *Request

Header set a header for the request.

func (*Request) Patch added in v1.13.0

func (r *Request) Patch(url string, body any) (*Response, error)

func (*Request) Post added in v1.13.0

func (r *Request) Post(url string, body any) (*Response, error)

func (*Request) Put added in v1.13.0

func (r *Request) Put(url string, body any) (*Response, error)

func (*Request) QueryParam added in v1.13.0

func (r *Request) QueryParam(key, value string) *Request

QueryParam sets query params

func (*Request) Retry added in v1.13.0

func (r *Request) Retry(maxRetries uint, baseDuration time.Duration, exponent float64) *Request

Retry configuration retrying on failure with exponential backoff.

Base duration of a second & an exponent of 2 is a good option.

type Response

type Response struct {
	// The underlying http.Response is embed into Response.
	*http.Response

	// Request is the Response's related Request.
	Request *Request
}

Response extends the stdlib http.Response type and extends its functionality

func (*Response) AsJSON added in v1.13.0

func (h *Response) AsJSON() (map[string]any, error)

func (*Response) AsString

func (r *Response) AsString() (string, error)

func (*Response) GetSSLAge added in v1.13.0

func (h *Response) GetSSLAge() *time.Duration

func (*Response) Into added in v1.13.0

func (r *Response) Into(dest any) error

func (*Response) IsJSON added in v1.13.0

func (h *Response) IsJSON() bool

func (*Response) IsOK

func (r *Response) IsOK(responseCodes ...int) bool

IsOK is a convenience method to determine if the response returned a 200 OK

type RetryConfig added in v1.13.0

type RetryConfig struct {
	// Number of retries to attempt
	MaxRetries uint

	// RetryWait specifies the base wait duration between retries
	RetryWait time.Duration

	// Amount to increase RetryWait with each failure, 2.0 is a good option for exponential backoff
	Factor float64
}

type RoundTripperFunc added in v1.13.0

type RoundTripperFunc func(*http.Request) (*http.Response, error)

func (RoundTripperFunc) RoundTrip added in v1.13.0

func (f RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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