middleware

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 4 Imported by: 8

Documentation

Overview

Package middleware provides middlewares for htt.Client as RoundTripperHandler

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(user, passwd string) func(http.RoundTripper) http.RoundTripper

BasicAuth middleware adds basic auth to request

func Header(key, value string) func(http.RoundTripper) http.RoundTripper

Header middleware adds a header to request

func JSON

JSON sets Content-Type and Accept headers to json

func MaxConcurrent

func MaxConcurrent(max int) func(http.RoundTripper) http.RoundTripper

MaxConcurrent middleware limits the total concurrency for a given requester

Types

type CircuitBreakerFunc

type CircuitBreakerFunc func(req func() (interface{}, error)) (interface{}, error)

CircuitBreakerFunc is an adapter to allow the use of ordinary functions as CircuitBreakerSvc.

func (CircuitBreakerFunc) Execute

func (c CircuitBreakerFunc) Execute(req func() (interface{}, error)) (interface{}, error)

Execute CircuitBreakerFunc

type CircuitBreakerSvc

type CircuitBreakerSvc interface {
	Execute(req func() (interface{}, error)) (interface{}, error)
}

CircuitBreakerSvc is an interface wrapping any function to send a request with circuit breaker. can be used with github.com/sony/gobreaker or any similar implementations

type RepeaterSvc

type RepeaterSvc interface {
	Do(ctx context.Context, fun func() error, errs ...error) (err error)
}

RepeaterSvc defines repeater interface

type RoundTripperFunc

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

RoundTripperFunc is a functional adapter for RoundTripperHandler

func (RoundTripperFunc) RoundTrip

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

RoundTrip adopts function to the type

type RoundTripperHandler

type RoundTripperHandler func(http.RoundTripper) http.RoundTripper

RoundTripperHandler is a type for middleware handler

func CircuitBreaker

func CircuitBreaker(svc CircuitBreakerSvc) RoundTripperHandler

CircuitBreaker middleware injects external CircuitBreakerSvc into the call chain

func Repeater

func Repeater(repeater RepeaterSvc, failOnCodes ...int) RoundTripperHandler

Repeater sets middleware with provided RepeaterSvc to retry failed requests

Directories

Path Synopsis
Package cache implements middleware for response caching.
Package cache implements middleware for response caching.
Package logger implements middleware for request logging.
Package logger implements middleware for request logging.

Jump to

Keyboard shortcuts

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