transport

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneRequest

func CloneRequest(r *http.Request) *http.Request

CloneRequest clones the HTTP request

func DrainBody

func DrainBody(b io.ReadCloser) (r1, r2 io.ReadCloser, err error)

DrainBody reads all of 'b' to memory and returns two equivalent ReadCloser instances with the same number of bytes

func IsRequestCacheable

func IsRequestCacheable(req *http.Request) bool

IsRequestCacheable returns true if the request is cacheable, false otherwise

func NewTransport

func NewTransport(rt http.RoundTripper, opts *TransportOpts) http.RoundTripper

NewTransport initializes Transport instances

Types

type CacheTransport

type CacheTransport struct {
	Next http.RoundTripper
	Opts *CacheTransportOptions

	Cache cache.Cache
}

CacheTransport implements http.RoundTripper

func NewCacheTransport

func NewCacheTransport(next http.RoundTripper, opts *CacheTransportOptions) *CacheTransport

NewCacheTransport initializes a new *CacheTransport instance

func (*CacheTransport) GetCacheKey

func (t *CacheTransport) GetCacheKey(req *http.Request) string

func (*CacheTransport) GetCachedResponse

func (t *CacheTransport) GetCachedResponse(req *http.Request) (*http.Response, error)

func (*CacheTransport) RoundTrip

func (t *CacheTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

type CacheTransportOptions

type CacheTransportOptions struct {
}

CacheTransportOptions are options for CacheTransport

type RatelimitTransport

type RatelimitTransport struct {
	Next    http.RoundTripper
	Options *RatelimitTransportOpts
}

RatelimitTransport implements http.RoundTripper

func NewRatelimitTransport

func NewRatelimitTransport(next http.RoundTripper, opts *RatelimitTransportOpts) *RatelimitTransport

NewRatelimitTransport initializes a new *RatelimitTransport instance

func (*RatelimitTransport) RoundTrip

func (t *RatelimitTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

type RatelimitTransportOpts

type RatelimitTransportOpts struct{}

RatelimitTransportOpts are options for RatelimitTransport

type ThrottleTransport

type ThrottleTransport struct {
	Next    http.RoundTripper
	Opts    *ThrottleTransportOptions
	Limiter ratelimit.Limiter
}

ThrottleTransport implements http.RoundTripper

func NewThrottleTransport

func NewThrottleTransport(next http.RoundTripper, opts *ThrottleTransportOptions) *ThrottleTransport

NewThrottleTransport initializes a new *ThrottleTransport instance

func (*ThrottleTransport) RoundTrip

func (t *ThrottleTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

type ThrottleTransportOptions

type ThrottleTransportOptions struct {
	RequestsPerSecond int
}

ThrottleTransportOptions are options for ThrottleTransport

type TransportOpts

type TransportOpts struct {
	RatelimitTransportEnabled bool
	RatelimitTransportOpts    *RatelimitTransportOpts

	ThrottleTransportEnabled bool
	ThrottleTransportOpts    *ThrottleTransportOptions

	CacheTransportEnabled bool
	CacheTransportOpts    *CacheTransportOptions
}

TransportOpts are options for creating new Transport instances

Jump to

Keyboard shortcuts

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