# README
httptripper
import "github.com/go-orion/Orion/utils/httptripper"
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)
Imported Packages
- github.com/afex/hystrix-go/hystrix
- github.com/go-orion/Orion/utils/httptripper/retry
- github.com/go-orion/Orion/utils/spanutils
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, method, url string, body io.Reader) (*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
Package files
func GetRequestRetrier
func GetRequestRetrier(req *http.Request) retry.Retriable
GetRequestRetrier fetches retrier to be used with this request
func GetRequestTraceName
func GetRequestTraceName(req *http.Request) string
GetRequestTraceName fetches a trace name from HTTP request
func NewHTTPClient
func NewHTTPClient(timeout time.Duration, options ...Option) *http.Client
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
func SetRequestRetrier(req *http.Request, retrier retry.Retriable) *http.Request
SetRequestRetrier sets the retrier to be used with this request
func SetRequestTraceName
func SetRequestTraceName(req *http.Request, traceName string) *http.Request
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
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
func WithHystrix(enabled bool) Option
WithHystrix enables/disables use of hystrix
func WithRetrier
func WithRetrier(retrier retry.Retriable) Option
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
Generated by godoc2ghmd