httpclient

package
v1.87.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package httpclient provides a configurable and instrumented HTTP client with common options. It includes a trace ID header support and common logging capabilities, including the ability to dump the redacted request and response messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client wraps the default HTTP client functionalities and adds logging and instrumentation capabilities.

func New

func New(opts ...Option) *Client

New creates a new HTTP client instance.

func (*Client) Do

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

Do performs the HTTP request with added trace ID and logging.

type DialContextFunc added in v1.82.0

type DialContextFunc func(ctx context.Context, network, address string) (net.Conn, error)

DialContextFunc is an alias for a net.Dialer.DialContext function.

type InstrumentRoundTripper

type InstrumentRoundTripper func(next http.RoundTripper) http.RoundTripper

InstrumentRoundTripper is an alias for a RoundTripper function.

type Option

type Option func(c *Client)

Option is the interface that allows to set client options.

func WithComponent

func WithComponent(name string) Option

WithComponent sets the component name to be used in logs.

func WithDialContext added in v1.82.0

func WithDialContext(fn DialContextFunc) Option

WithDialContext sets the DialContext function for the HTTP client. The DialContext function is used to establish network connections. It allows customizing the behavior of the client's underlying transport.

func WithLogPrefix

func WithLogPrefix(prefix string) Option

WithLogPrefix specifies a string prefix to be added to each log field name in the Do method.

func WithRedactFn

func WithRedactFn(fn RedactFn) Option

WithRedactFn set the function used to redact HTTP request and response dumps in the logs.

func WithRoundTripper

func WithRoundTripper(fn InstrumentRoundTripper) Option

WithRoundTripper wraps the HTTP client Transport with the specified RoundTripper function.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout overrides the default client timeout.

func WithTraceIDHeaderName

func WithTraceIDHeaderName(name string) Option

WithTraceIDHeaderName sets the trace id header name.

type RedactFn

type RedactFn func(s string) string

RedactFn is an alias for a redact function.

Jump to

Keyboard shortcuts

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