Documentation ¶
Overview ¶
Package httptripper provides an implementation of http.RoundTripper that provides retries, popluates opentracing span info and hystrix circuit breaker.
Setup ¶
for most cases using the http.Client provided by the package is sufficient
client := httptripper.NewHTTPClient(time.Millisecond * 500)
Note: If you are using a custom http.Client, then just wrap your custom http.Client using httptripper.WrapTripper
tripper := httptripper.WrapTripper(client.Transport) client.Transport = tripper
How To Use ¶
Make sure you use httptripper.NewRequest to build http.Request, since http.NewRequest does not take context as parameter
httpReq, err := httptripper.NewRequest(ctx, "TracingName", "GET", url, nil)
Index ¶
- func GetRequestRetrier(req *http.Request) retry.Retriable
- func GetRequestTraceName(req *http.Request) string
- func NewHTTPClient(timeout time.Duration, options ...Option) *http.Client
- func NewRequest(ctx context.Context, traceName, method, url string, body io.Reader) (*http.Request, error)
- func NewRequestWithRetrier(ctx context.Context, traceName string, retrier retry.Retriable, ...) (*http.Request, error)
- func NewTripper(options ...Option) http.RoundTripper
- func SetRequestRetrier(req *http.Request, retrier retry.Retriable) *http.Request
- func SetRequestTraceName(req *http.Request, traceName string) *http.Request
- func WrapTripper(base http.RoundTripper) http.RoundTripper
- type Option
- type OptionsData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRequestRetrier ¶
GetRequestRetrier fetches retrier to be used with this request
func GetRequestTraceName ¶
GetRequestTraceName fetches a trace name from HTTP request
func NewHTTPClient ¶
NewHTTPClient creates a new http.Client with default retry options and timeout
func NewRequest ¶
func NewRequest(ctx context.Context, traceName, method, url string, body io.Reader) (*http.Request, error)
NewRequest extends http.NewRequest with context and trace name
func NewRequestWithRetrier ¶
func NewRequestWithRetrier(ctx context.Context, traceName string, retrier retry.Retriable, method, url string, body io.Reader) (*http.Request, error)
NewRequestWithRetrier extends http.NewRequest with context, trace name and retrier
func NewTripper ¶
func NewTripper(options ...Option) http.RoundTripper
NewTripper returns a default tripper wrapped around http.DefaultTransport
func SetRequestRetrier ¶
SetRequestRetrier sets the retrier to be used with this request
func SetRequestTraceName ¶
SetRequestTraceName stores a trace name in a HTTP request
func WrapTripper ¶
func WrapTripper(base http.RoundTripper) http.RoundTripper
WrapTripper wraps the base tripper with zipkin info
Types ¶
type Option ¶
type Option func(*OptionsData)
Option defines an options for Tripper
func WithBaseTripper ¶
func WithBaseTripper(base http.RoundTripper) Option
WithBaseTripper updates the tripper to use the provided http.RoundTripper
func WithHystrix ¶
WithHystrix enables/disables use of hystrix
func WithRetrier ¶
WithRetrier updates the tripper to use the provided retry.Retriable
type OptionsData ¶
type OptionsData struct { BaseTripper http.RoundTripper HystrixEnabled bool Retrier retry.Retriable }
OptionsData is the data polulated by the options
Directories ¶
Path | Synopsis |
---|---|
Package retry provides an implementation for retrying http requests with multiple wait strategies
|
Package retry provides an implementation for retrying http requests with multiple wait strategies |
Package strategy provides strategies for use with retry
|
Package strategy provides strategies for use with retry |