middleware

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyMiddleware = emptyMiddleware{}
View Source
var ErrNotFound = errors.New("Middleware has not been registered")

ErrNotFound is middleware not found.

View Source
var LOG = log.NewHelper(log.With(log.GetLogger(), "source", "middleware"))

Functions

func EndpointFromContext

func EndpointFromContext(ctx context.Context) (*config.Endpoint, bool)

EndpointFromContext returns endpoint config from context.

func NewRequestContext

func NewRequestContext(ctx context.Context, o *RequestOptions) context.Context

NewRequestContext returns a new Context that carries value.

func Register

func Register(name string, factory Factory)

Register registers one middleware.

func RegisterV2

func RegisterV2(name string, factory FactoryV2)

RegisterV2 registers one v2 middleware.

func RequestBackendsFromContext

func RequestBackendsFromContext(ctx context.Context) ([]string, bool)

RequestBackendsFromContext returns backend nodes from context.

func SelectorFiltersFromContext

func SelectorFiltersFromContext(ctx context.Context) ([]selector.NodeFilter, bool)

SelectorFiltersFromContext returns selector filter from context.

func WithRequestBackends

func WithRequestBackends(ctx context.Context, backend ...string) context.Context

WithRequestBackends with backend nodes into context.

func WithSelectorFitler

func WithSelectorFitler(ctx context.Context, fn selector.NodeFilter) context.Context

WithSelectorFitler with selector filter into context.

Types

type Factory

type Factory func(*config.Middleware) (Middleware, error)

Factory is a middleware factory.

type FactoryV2

type FactoryV2 func(*config.Middleware) (MiddlewareV2, error)

type MetricsLabels

type MetricsLabels interface {
	Protocol() string
	Method() string
	Path() string
	Service() string
	BasePath() string
}

func MetricsLabelsFromContext

func MetricsLabelsFromContext(ctx context.Context) (MetricsLabels, bool)

func NewMetricsLabels

func NewMetricsLabels(ep *config.Endpoint) MetricsLabels

type Middleware

type Middleware func(http.RoundTripper) http.RoundTripper

Middleware is handler middleware.

func (Middleware) Close

func (f Middleware) Close() error

func (Middleware) Process

type MiddlewareV2

type MiddlewareV2 interface {
	Process(http.RoundTripper) http.RoundTripper
	io.Closer
}

func Create

func Create(cfg *config.Middleware) (MiddlewareV2, error)

Create instantiates a middleware based on `cfg`.

func NewWithCloser

func NewWithCloser(process Middleware, closer io.Closer) MiddlewareV2

type Registry

type Registry interface {
	Register(name string, factory Factory)
	RegisterV2(name string, factory FactoryV2)
	Create(cfg *config.Middleware) (MiddlewareV2, error)
}

Registry is the interface for callers to get registered middleware.

func NewRegistry

func NewRegistry() Registry

NewRegistry returns a new middleware registry.

type RequestOptions

type RequestOptions struct {
	Endpoint             *config.Endpoint
	Filters              []selector.NodeFilter
	Backends             []string
	Metadata             map[string]string
	UpstreamStatusCode   []int
	UpstreamResponseTime []float64
	CurrentNode          selector.Node
	DoneFunc             selector.DoneFunc
	LastAttempt          bool
	Values               RequestValues
}

RequestOptions is a request option.

func FromRequestContext

func FromRequestContext(ctx context.Context) (*RequestOptions, bool)

FromRequestContext returns request options from context.

func NewRequestOptions

func NewRequestOptions(c *config.Endpoint) *RequestOptions

NewRequestOptions new a request options with retry filter.

type RequestValues

type RequestValues interface {
	Get(key any) (any, bool)
	Set(key, val any)
}

type RoundTripperFunc

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

RoundTripperFunc is an adapter to allow the use of ordinary functions as HTTP RoundTripper.

func (RoundTripperFunc) RoundTrip

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

RoundTrip calls f(w, r).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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