client

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package client make easy to use an http client

Index

Constants

View Source
const PrefixHTTP = "HTTP_"

PrefixHTTP is the env prefix of Config environment variables.

Variables

This section is empty.

Functions

func NewHTTPClient

func NewHTTPClient(tracer telemetry.Tracer, opts ...func(*http.Client)) *http.Client

NewHTTPClient crate a new *http.Client with Config fields set. If parent is present only config fields are changed.

func WithLogger added in v1.0.0

func WithLogger(c *http.Client, log log.Logger, acceptedStatusCode []string)

WithLogger wrap http client transport with log. If response code does not match any acceptedStatusCode, response body is logged.

Types

type Config

type Config struct {
	Timeout                time.Duration `env:"TIMEOUT,required"`
	RoundtripperStatusCode []string      `env:"ROUNDTRIPPER_STATUSCODE,default=2.."`
}

Config of the http client.

func (Config) SetTimeout

func (c Config) SetTimeout(client *http.Client)

SetTimeout set request timeout.

type HeaderTripper added in v1.0.0

type HeaderTripper struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

HeaderTripper wrap http.RoundTripper to enrich with log. This way all outgoing requests (even bodies) will be logged.

func NewLogTripper added in v1.0.0

func NewLogTripper(parent http.RoundTripper, log log.Logger, acceptedStatusCodes []string) *HeaderTripper

NewLogTripper creates a new HeaderTripper using parent http.RoundTripper with log logger and will log responses bodies if no acceptedSatusCodes match (regex are accepted).

func (*HeaderTripper) RoundTrip added in v1.0.0

func (rt *HeaderTripper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip refer to http.RoundTripper.

Jump to

Keyboard shortcuts

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