package
0.0.0-20190220103131-045890faf5e6
Repository: https://github.com/go-orion/orion.git
Documentation: pkg.go.dev

# 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

Index

Package files

httptripper.go types.go

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

# Packages

Package strategy provides strategies for use with retry */.

# Functions

GetRequestRetrier fetches retrier to be used with this request.
GetRequestTraceName fetches a trace name from HTTP request.
NewHTTPClient creates a new http.Client with default retry options and timeout.
NewRequest extends http.NewRequest with context and trace name.
NewRequestWithRetrier extends http.NewRequest with context, trace name and retrier.
NewTripper returns a default tripper wrapped around http.DefaultTransport.
SetRequestRetrier sets the retrier to be used with this request.
SetRequestTraceName stores a trace name in a HTTP request.
WithBaseTripper updates the tripper to use the provided http.RoundTripper.
WithHystrix enables/disables use of hystrix.
WithRetrier updates the tripper to use the provided retry.Retriable.
WrapTripper wraps the base tripper with zipkin info.

# Structs

OptionsData is the data polulated by the options.

# Type aliases

Option defines an options for Tripper.