proxy

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: Apache-2.0 Imports: 22 Imported by: 40

Documentation

Overview

Package proxy provides proxy and proxy middleware interfaces and implementations

Index

Constants

View Source
const Namespace = "github.com/starvn/turbo/proxy"

Variables

View Source
var (
	ErrNoBackends       = errors.New("all endpoints must have at least one backend")
	ErrTooManyBackends  = errors.New("too many backends for this proxy")
	ErrTooManyProxies   = errors.New("too many proxies for this proxy middleware")
	ErrNotEnoughProxies = errors.New("not enough proxies for this endpoint")
)
View Source
var DefaultHTTPResponseParserConfig = HTTPResponseParserConfig{
	func(_ io.Reader, _ *map[string]interface{}) error { return nil },
	EntityFormatterFunc(func(r Response) Response { return r }),
}

Functions

func AllowlistPrune

func AllowlistPrune(wlDict map[string]interface{}, inDict map[string]interface{}) bool

func CloneRequestHeaders

func CloneRequestHeaders(headers map[string][]string) map[string][]string

func CloneRequestParams

func CloneRequestParams(params map[string]string) map[string]string

func NewReadCloserWrapper

func NewReadCloserWrapper(ctx context.Context, in io.ReadCloser) io.Reader

func RegisterResponseCombiner

func RegisterResponseCombiner(name string, f ResponseCombiner)

Types

type BackendFactory

type BackendFactory func(remote *config.Backend) Proxy

func CustomHTTPProxyFactory

func CustomHTTPProxyFactory(cf client.HTTPClientFactory) BackendFactory

func HTTPProxyFactory

func HTTPProxyFactory(client *http.Client) BackendFactory

type EntityFormatter

type EntityFormatter interface {
	Format(Response) Response
}

func NewEntityFormatter

func NewEntityFormatter(remote *config.Backend) EntityFormatter

type EntityFormatterFunc

type EntityFormatterFunc func(Response) Response

func (EntityFormatterFunc) Format

func (e EntityFormatterFunc) Format(entity Response) Response

type Factory

type Factory interface {
	New(cfg *config.EndpointConfig) (Proxy, error)
}

func DefaultFactory

func DefaultFactory(logger log.Logger) Factory

func DefaultFactoryWithSubscriber

func DefaultFactoryWithSubscriber(logger log.Logger, sF discovery.SubscriberFactory) Factory

func NewDefaultFactory

func NewDefaultFactory(backendFactory BackendFactory, logger log.Logger) Factory

func NewDefaultFactoryWithSubscriber

func NewDefaultFactoryWithSubscriber(backendFactory BackendFactory, logger log.Logger, sF discovery.SubscriberFactory) Factory

func NewShadowFactory

func NewShadowFactory(f Factory) Factory

type FactoryFunc

type FactoryFunc func(*config.EndpointConfig) (Proxy, error)

func (FactoryFunc) New

func (f FactoryFunc) New(cfg *config.EndpointConfig) (Proxy, error)

type HTTPResponseParser

type HTTPResponseParser func(context.Context, *http.Response) (*Response, error)

func DefaultHTTPResponseParserFactory

func DefaultHTTPResponseParserFactory(cfg HTTPResponseParserConfig) HTTPResponseParser

type HTTPResponseParserConfig

type HTTPResponseParserConfig struct {
	Decoder         encoding.Decoder
	EntityFormatter EntityFormatter
}

type HTTPResponseParserFactory

type HTTPResponseParserFactory func(HTTPResponseParserConfig) HTTPResponseParser

type Metadata

type Metadata struct {
	Headers    map[string][]string
	StatusCode int
}

type Middleware

type Middleware func(next ...Proxy) Proxy

func NewBackendPluginMiddleware

func NewBackendPluginMiddleware(remote *config.Backend) Middleware

func NewConcurrentMiddleware

func NewConcurrentMiddleware(remote *config.Backend) Middleware

func NewFlatmapMiddleware

func NewFlatmapMiddleware(cfg *config.EndpointConfig) Middleware

func NewGraphQLMiddleware

func NewGraphQLMiddleware(remote *config.Backend) Middleware

func NewLoadBalancedMiddleware

func NewLoadBalancedMiddleware(remote *config.Backend) Middleware

func NewLoadBalancedMiddlewareWithSubscriber

func NewLoadBalancedMiddlewareWithSubscriber(subscriber discovery.Subscriber) Middleware

func NewLoggingMiddleware

func NewLoggingMiddleware(logger log.Logger, name string) Middleware

func NewMergeDataMiddleware

func NewMergeDataMiddleware(endpointConfig *config.EndpointConfig) Middleware

func NewPluginMiddleware

func NewPluginMiddleware(endpoint *config.EndpointConfig) Middleware

func NewRandomLoadBalancedMiddleware

func NewRandomLoadBalancedMiddleware(remote *config.Backend) Middleware

func NewRandomLoadBalancedMiddlewareWithSubscriber

func NewRandomLoadBalancedMiddlewareWithSubscriber(subscriber discovery.Subscriber) Middleware

func NewRequestBuilderMiddleware

func NewRequestBuilderMiddleware(remote *config.Backend) Middleware

func NewRoundRobinLoadBalancedMiddleware

func NewRoundRobinLoadBalancedMiddleware(remote *config.Backend) Middleware

func NewRoundRobinLoadBalancedMiddlewareWithSubscriber

func NewRoundRobinLoadBalancedMiddlewareWithSubscriber(subscriber discovery.Subscriber) Middleware

func NewStaticMiddleware

func NewStaticMiddleware(endpointConfig *config.EndpointConfig) Middleware

type Proxy

type Proxy func(ctx context.Context, request *Request) (*Response, error)

func EmptyMiddleware

func EmptyMiddleware(next ...Proxy) Proxy

func NewHTTPProxy

func NewHTTPProxy(remote *config.Backend, cf client.HTTPClientFactory, decode encoding.Decoder) Proxy

func NewHTTPProxyWithHTTPExecutor

func NewHTTPProxyWithHTTPExecutor(remote *config.Backend, re client.HTTPRequestExecutor, dec encoding.Decoder) Proxy

func NewShadowProxy

func NewShadowProxy(p1, p2 Proxy) Proxy

func ShadowMiddleware

func ShadowMiddleware(next ...Proxy) Proxy

type Register

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

func NewRegister

func NewRegister() *Register

func (Register) GetResponseCombiner

func (r Register) GetResponseCombiner(name string) (ResponseCombiner, bool)

func (Register) SetResponseCombiner

func (r Register) SetResponseCombiner(name string, rc ResponseCombiner)

type Request

type Request struct {
	Method  string
	URL     *url.URL
	Query   url.Values
	Path    string
	Body    io.ReadCloser
	Params  map[string]string
	Headers map[string][]string
}

func CloneRequest

func CloneRequest(r *Request) *Request

func (*Request) Clone

func (r *Request) Clone() Request

func (*Request) GeneratePath

func (r *Request) GeneratePath(URLPattern string)

type RequestWrapper

type RequestWrapper interface {
	Params() map[string]string
	Headers() map[string][]string
	Body() io.ReadCloser
	Method() string
	URL() *url.URL
	Query() url.Values
	Path() string
}

type Response

type Response struct {
	Data       map[string]interface{}
	IsComplete bool
	Metadata   Metadata
	Io         io.Reader
}

func NoOpHTTPResponseParser

func NoOpHTTPResponseParser(ctx context.Context, resp *http.Response) (*Response, error)

func NoopProxy

func NoopProxy(_ context.Context, _ *Request) (*Response, error)

type ResponseCombiner

type ResponseCombiner func(int, []*Response) *Response

type ResponseMetadataWrapper

type ResponseMetadataWrapper interface {
	Headers() map[string][]string
	StatusCode() int
}

type ResponseWrapper

type ResponseWrapper interface {
	Data() map[string]interface{}
	Io() io.Reader
	IsComplete() bool
	Metadata() ResponseMetadataWrapper
}

Directories

Path Synopsis
Package plugin provides tools for loading and registering proxy plugins
Package plugin provides tools for loading and registering proxy plugins

Jump to

Keyboard shortcuts

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