httptripper

package
v0.0.0-...-045890f Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

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

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

Constants

This section is empty.

Variables

This section is empty.

Functions

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

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

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

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

Jump to

Keyboard shortcuts

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