Documentation
¶
Index ¶
Constants ¶
const ( HeaderXRequestId = "x-request-id" HeaderTraceParent = "traceparent" )
Variables ¶
This section is empty.
Functions ¶
func CopyObservabilityRequestHeaders ¶
CopyObservabilityRequestHeaders performs a copy of x-request-id and traceparent headers between two http.Request.
func CopyRequestHeaders ¶
CopyRequestHeaders performs a copy of a specified list of headers between two http.Request.
Types ¶
type DefaultHttpClientFactory ¶
type DefaultHttpClientFactory struct{}
DefaultHttpClientFactory is the default HttpClientFactory implementation.
func (*DefaultHttpClientFactory) Create ¶
func (f *DefaultHttpClientFactory) Create(options ...HttpClientOption) (*http.Client, error)
Create returns a new http.Client, and accepts a list of HttpClientOption. For example:
var client, _ = httpclient.NewDefaultHttpClientFactory().Create() // equivalent to: var client, _ = httpclient.NewDefaultHttpClientFactory().Create( httpclient.WithTransport(transport.NewBaseTransport()), // base http transport (optimized) httpclient.WithTimeout(30*time.Second), // 30 seconds timeout httpclient.WithCheckRedirect(nil), // default redirection checks httpclient.WithCookieJar(nil), // default cookie jar )
type HttpClientFactory ¶
type HttpClientFactory interface {
Create(opts ...HttpClientOption) (*http.Client, error)
}
HttpClientFactory is the interface for http.Client factories.
func NewDefaultHttpClientFactory ¶
func NewDefaultHttpClientFactory() HttpClientFactory
NewDefaultHttpClientFactory returns a DefaultHttpClientFactory, implementing HttpClientFactory.
type HttpClientOption ¶
type HttpClientOption func(o *Options)
HttpClientOption are functional options for the HttpClientFactory implementations.
func WithCheckRedirect ¶
WithCheckRedirect is used to specify the check redirect func to use by the http.Client.
func WithCookieJar ¶
func WithCookieJar(j http.CookieJar) HttpClientOption
WithCookieJar is used to specify the http.CookieJar to use by the http.Client.
func WithTimeout ¶
func WithTimeout(t time.Duration) HttpClientOption
WithTimeout is used to specify the timeout to use by the http.Client.
func WithTransport ¶
func WithTransport(t http.RoundTripper) HttpClientOption
WithTransport is used to specify the http.RoundTripper to use by the http.Client.
type Options ¶
type Options struct { Transport http.RoundTripper CheckRedirect func(req *http.Request, via []*http.Request) error Jar http.CookieJar Timeout time.Duration }
Options are options for the HttpClientFactory implementations.
func DefaultHttpClientOptions ¶
func DefaultHttpClientOptions() Options
DefaultHttpClientOptions are the default options used in the DefaultHttpClientFactory.