clihttp

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package clihttp adds opentracing support to http client.

Example
client := NewClient(opentracing.GlobalTracer())
req, _ := http.NewRequest("GET", "https://example.com/", nil)
resp, _ := client.Do(req)
resp.Body.Close()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Providers added in v0.10.3

func Providers(options ...ProvidersOptionFunc) di.Deps

Providers provides the http client as a dependency. Depends On:

opentracing.Tracer

Provides:

*clihttp.Client

Types

type Client

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

Client is a http client that traces http requests.

func NewClient

func NewClient(tracer opentracing.Tracer, options ...Option) *Client

NewClient creates a Client with tracing support.

func (*Client) Do

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

Do sends the request.

type ClientArgs added in v0.10.3

type ClientArgs struct {
	Populator contract.DIPopulator
}

ClientArgs is the constructor argument for WithClientConstructor. See WithClientConstructor for usage.

type HttpDoer

type HttpDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HttpDoer modules a upstream http client.

type Option

type Option func(*Client)

Option changes the behavior of Client.

func WithDoer

func WithDoer(doer contract.HttpDoer) Option

WithDoer is an option that accepts a HttpDoer as the underlying client.

func WithRequestLogThreshold

func WithRequestLogThreshold(num int) Option

WithRequestLogThreshold is options that sets threshold of request logging in number of bytes. If the payload is larger than this threshold, the log will be omit.

func WithResponseLogThreshold

func WithResponseLogThreshold(num int) Option

WithResponseLogThreshold is options that sets threshold of response logging in number of bytes. If the response body is larger than this threshold, the log will be omit.

type ProvidersOptionFunc added in v0.10.3

type ProvidersOptionFunc func(options *providersOption)

ProvidersOptionFunc is the type of functional providersOption for Providers. Use this type to change how Providers work.

func WithClientConstructor added in v0.10.3

func WithClientConstructor(f func(args ClientArgs) (contract.HttpDoer, error)) ProvidersOptionFunc

WithClientConstructor instructs the Providers to accept an alternative constructor for the contract.HttpDoer to be wrapped by clihttp.NewClient.

func WithClientOption added in v0.10.3

func WithClientOption(options ...Option) ProvidersOptionFunc

WithClientOption instructs the Providers to accept additional options for the NewClient call, such as WithRequestLogThreshold.

Jump to

Keyboard shortcuts

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