proxy

package
v0.0.0-...-6582c30 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package proxy provides proxy and proxy middleware interfaces and implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoBackends is the error returned when an endpoint has no backends defined
	ErrNoBackends = errors.New("all endpoints must have at least one backend")
	// ErrTooManyBackends is the error returned when an endpoint has too many backends defined
	ErrTooManyBackends = errors.New("too many backends for this proxy")
	// ErrTooManyProxies is the error returned when a middleware has too many proxies defined
	ErrTooManyProxies = errors.New("too many proxies for this proxy middleware")
	// ErrNotEnoughProxies is the error returned when an endpoint has not enough proxies defined
	ErrNotEnoughProxies = errors.New("not enough proxies for this endpoint")
)
View Source
var ErrInvalidStatusCode = errors.New("Invalid status code")

ErrInvalidStatusCode is the error returned by the http proxy when the received status code is not a 200 nor a 201

Functions

func NewHTTPClient

func NewHTTPClient(_ context.Context) *http.Client

NewHTTPClient just creates a http default client

Types

type BackendFactory

type BackendFactory func(remote *config.Backend) Proxy

BackendFactory creates a proxy based on the received backend configuration

func CustomHTTPProxyFactory

func CustomHTTPProxyFactory(cf HTTPClientFactory) BackendFactory

CustomHTTPProxyFactory returns a BackendFactory. The Proxies it creates will use the received HTTPClientFactory

func HTTPProxyFactory

func HTTPProxyFactory(client *http.Client) BackendFactory

HTTPProxyFactory returns a BackendFactory. The Proxies it creates will use the received net/http.Client

type EntityFormatter

type EntityFormatter interface {
	Format(entity Response) Response
}

EntityFormatter formats the response data

func NewEntityFormatter

func NewEntityFormatter(target string, whitelist, blacklist []string, group string, mappings map[string]string) EntityFormatter

NewEntityFormatter creates an entity formatter with the received params

type Factory

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

Factory creates proxies based on the received endpoint configuration.

Both, factories and backend factories, create proxies but factories are designed as a stack makers because they are intended to generate the complete proxy stack for a given frontend endpoint the app would expose and they could wrap several proxies provided by a backend factory

func DefaultFactory

func DefaultFactory(logger logging.Logger) Factory

DefaultFactory returns a default http proxy factory with the injected logger

func DefaultFactoryWithSubscriber

func DefaultFactoryWithSubscriber(logger logging.Logger, sF sd.SubscriberFactory) Factory

DefaultFactoryWithSubscriber returns a default proxy factory with the injected logger and subscriber factory

func NewDefaultFactory

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

NewDefaultFactory returns a default proxy factory with the injected proxy builder and logger

func NewDefaultFactoryWithSubscriber

func NewDefaultFactoryWithSubscriber(backendFactory BackendFactory, logger logging.Logger, sF sd.SubscriberFactory) Factory

NewDefaultFactoryWithSubscriber returns a default proxy factory with the injected proxy builder, logger and subscriber factory

type HTTPClientFactory

type HTTPClientFactory func(ctx context.Context) *http.Client

HTTPClientFactory creates http clients based with the received context

type HTTPRequestExecutor

type HTTPRequestExecutor func(ctx context.Context, req *http.Request) (*http.Response, error)

HTTPRequestExecutor defines the interface of the request executor for the HTTP transport protocol

func DefaultHTTPRequestExecutor

func DefaultHTTPRequestExecutor(clientFactory HTTPClientFactory) HTTPRequestExecutor

DefaultHTTPRequestExecutor creates a HTTPRequestExecutor with the received HTTPClientFactory

type Middleware

type Middleware func(next ...Proxy) Proxy

Middleware adds a middleware, decorator or wrapper over a collection of proxies, exposing a proxy interface.

Proxy middlewares can be stacked:

var p Proxy
p := EmptyMiddleware(NoopProxy)
response, err := p(ctx, r)

func NewConcurrentMiddleware

func NewConcurrentMiddleware(remote *config.Backend) Middleware

NewConcurrentMiddleware creates a proxy middleware that enables sending several requests concurrently

func NewLoggingMiddleware

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

NewLoggingMiddleware creates proxy middleware for logging requests and responses

func NewMergeDataMiddleware

func NewMergeDataMiddleware(endpointConfig *config.EndpointConfig) Middleware

NewMergeDataMiddleware creates proxy middleware for merging responses from several backends

func NewRandomLoadBalancedMiddleware

func NewRandomLoadBalancedMiddleware(remote *config.Backend) Middleware

NewRandomLoadBalancedMiddleware creates proxy middleware adding a random balancer over a default subscriber

func NewRandomLoadBalancedMiddlewareWithSubscriber

func NewRandomLoadBalancedMiddlewareWithSubscriber(subscriber sd.Subscriber) Middleware

NewRandomLoadBalancedMiddlewareWithSubscriber creates proxy middleware adding a random balancer over the received subscriber

func NewRequestBuilderMiddleware

func NewRequestBuilderMiddleware(remote *config.Backend) Middleware

NewRequestBuilderMiddleware creates a proxy middleware that parses the request params received from the outter layer and generates the path to the backend endpoints

func NewRoundRobinLoadBalancedMiddleware

func NewRoundRobinLoadBalancedMiddleware(remote *config.Backend) Middleware

NewRoundRobinLoadBalancedMiddleware creates proxy middleware adding a round robin balancer over a default subscriber

func NewRoundRobinLoadBalancedMiddlewareWithSubscriber

func NewRoundRobinLoadBalancedMiddlewareWithSubscriber(subscriber sd.Subscriber) Middleware

NewRoundRobinLoadBalancedMiddlewareWithSubscriber creates proxy middleware adding a round robin balancer over the received subscriber

type Proxy

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

Proxy processes a request in a given context and returns a response and an error

func EmptyMiddleware

func EmptyMiddleware(next ...Proxy) Proxy

EmptyMiddleware is a dummy middleware, useful for testing and fallback

func NewHTTPProxy

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

NewHTTPProxy creates a http proxy with the injected configuration, HTTPClientFactory and Decoder

func NewHTTPProxyWithHTTPExecutor

func NewHTTPProxyWithHTTPExecutor(remote *config.Backend, requestExecutor HTTPRequestExecutor, decode encoding.Decoder) Proxy

NewHTTPProxyWithHTTPExecutor creates a http proxy with the injected configuration, HTTPRequestExecutor and Decoder

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
}

Request contains the data to send to the backend

func (*Request) Clone

func (r *Request) Clone() Request

Clone clones itself into a new request

func (*Request) GeneratePath

func (r *Request) GeneratePath(URLPattern string)

GeneratePath takes a pattern and updates the path of the request

type Response

type Response struct {
	Data       map[string]interface{}
	IsComplete bool
}

Response is the entity returned by the proxy

func NoopProxy

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

NoopProxy is a do nothing proxy, useful for testing

Source Files

  • balancing.go
  • concurrent.go
  • factory.go
  • formatter.go
  • http.go
  • logging.go
  • merging.go
  • proxy.go
  • request.go

Jump to

Keyboard shortcuts

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