httpclient

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCircuitBreaker

func DefaultCircuitBreaker(name string) *gobreaker.CircuitBreaker

DefaultCircuitBreaker .

func DefaultFailedExecutionStatus

func DefaultFailedExecutionStatus() []int

DefaultFailedExecutionStatus .

func DefaultObserveOption added in v1.0.4

func DefaultObserveOption(name string, r *http.Request, w *http.Response) prometheus.Labels

DefaultObserveOption .

func NewInstrumentation

func NewInstrumentation(histogram *prometheus.HistogramVec, name string, c *http.Client, opts ...ObserveOption) *http.Client

NewInstrumentation .

func NewRetryable

func NewRetryable(conf RetryableConfig, c *http.Client) *http.Client

NewRetryable this is wrapper for `go-retryablehttp`. which has base from `net/http.Client` itself Make it as `net/http.Client` again

func NewWithDefaultInstrumentation

func NewWithDefaultInstrumentation(name string, c *http.Client) *http.Client

NewWithDefaultInstrumentation .

func RegexedObserveOption added in v1.0.4

func RegexedObserveOption(regs map[string]string) func(name string, r *http.Request, w *http.Response) prometheus.Labels

RegexedObserveOption option add regex format for changing unique url path into general one, with keep other path that not provided on regex such as extra path on URL like`secure.payfazz.com/service-name`. Usually service-name will be generated when creating domain. Make sure to sort regex descending (longest to shortest)

`ex:` /service-name/user/123 to /service-name/user/{userId} `ex: /user/123 to /user/{userId}`

Types

type CircuitBreaker

type CircuitBreaker struct {
	// contains filtered or unexported fields
}

CircuitBreaker .

func NewCircuitBreaker

func NewCircuitBreaker(name string, c *http.Client) *CircuitBreaker

NewCircuitBreaker .

func (*CircuitBreaker) Do

func (c *CircuitBreaker) Do(req *http.Request) (*http.Response, error)

Do .

func (*CircuitBreaker) SetFailedExecutionStatus

func (c *CircuitBreaker) SetFailedExecutionStatus(status ...int) *CircuitBreaker

SetFailedExecutionStatus overriding failed execution status

func (*CircuitBreaker) StandardClient

func (c *CircuitBreaker) StandardClient() *http.Client

StandardClient .

func (*CircuitBreaker) UseCircuitBreaker

func (c *CircuitBreaker) UseCircuitBreaker(cb *gobreaker.CircuitBreaker) *CircuitBreaker

UseCircuitBreaker overriding ciruitbreaker system

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer an interface to wrap net/http Client at first. Of course, net/http Client is usable without wrapper if you want to use it at the first. The purpose of this interface is make your implementation to third party using http method not mixed up with business things. Such as logging http request and response, request duration, retryable request, instrumentation, etc.

Even better with this interface, you can make more wrapper for whatever your needs. Sample wrapper is `LoggedDoer` which logging the request.

type ObserveOption added in v1.0.4

type ObserveOption func(name string, r *http.Request, w *http.Response) prometheus.Labels

ObserveOption .

type RetryableConfig

type RetryableConfig struct {
	RetryMax     int
	RetryWaitMin time.Duration
	RetryWaitMax time.Duration
}

RetryableConfig .

func DefaultRetryableConfig

func DefaultRetryableConfig() RetryableConfig

DefaultRetryableConfig .

type RoundTripperFunc

type RoundTripperFunc func(req *http.Request) (*http.Response, error)

The RoundTripperFunc type is an adapter to allow the use of ordinary functions as RoundTrippers. If f is a function with the appropriate signature, RountTripperFunc(f) is a RoundTripper that calls f.

func (RoundTripperFunc) RoundTrip

func (rt RoundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

Jump to

Keyboard shortcuts

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