proxy

package
v0.0.0-...-b40c5a5 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2018 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultIdleConnsPerHost the default value set for http.Transport.MaxIdleConnsPerHost.
	DefaultIdleConnsPerHost = 64

	// DefaultCloseIdleConnsPeriod the default period at which the idle connections are forcibly
	// closed.
	DefaultCloseIdleConnsPeriod = 20 * time.Second
)

Variables

View Source
var (
	// ErrEmptyBackendList is used when the list of beckends is empty
	ErrEmptyBackendList = errors.New("can not elect backend, Backends empty")
	// ErrZeroWeight is used when there a zero value weight was given
	ErrZeroWeight = errors.New("invalid backend, weight 0 given")
	// ErrCannotElectBackend is used a backend cannot be elected
	ErrCannotElectBackend = errors.New("cant elect backend")
)
View Source
var (
	// ErrUnsupportedAlgorithm is used when an unsupported algorithm is given
	ErrUnsupportedAlgorithm = errors.New("unsupported balancing algorithm")
)

Functions

This section is empty.

Types

type Balancer

type Balancer interface {
	Elect(hosts []*Target) (*Target, error)
}

Balancer holds the load balancer methods for many different algorithms

func NewBalancer

func NewBalancer(balance string) (Balancer, error)

NewBalancer creates a new Balancer based on balancing strategy

type Definition

type Definition struct {
	PreserveHost        bool       `bson:"preserve_host" json:"preserve_host" mapstructure:"preserve_host"`
	ListenPath          string     `bson:"listen_path" json:"listen_path" mapstructure:"listen_path" valid:"required~proxy.listen_path is required,urlpath"`
	Upstreams           *Upstreams `bson:"upstreams" json:"upstreams" mapstructure:"upstreams"`
	InsecureSkipVerify  bool       `bson:"insecure_skip_verify" json:"insecure_skip_verify" mapstructure:"insecure_skip_verify"`
	StripPath           bool       `bson:"strip_path" json:"strip_path" mapstructure:"strip_path"`
	AppendPath          bool       `bson:"append_path" json:"append_path" mapstructure:"append_path"`
	EnableLoadBalancing bool       `bson:"enable_load_balancing" json:"enable_load_balancing" mapstructure:"enable_load_balancing"`
	Methods             []string   `bson:"methods" json:"methods"`
	Hosts               []string   `bson:"hosts" json:"hosts"`
}

Definition defines proxy rules for a route

func NewDefinition

func NewDefinition() *Definition

NewDefinition creates a new Proxy Definition with default values

func (*Definition) IsBalancerDefined

func (d *Definition) IsBalancerDefined() bool

IsBalancerDefined checks if load balancer is defined

func (*Definition) Validate

func (d *Definition) Validate() (bool, error)

Validate validates proxy data

type InChain

type InChain []router.Constructor

InChain typed array for inbound plugin sequence, normally this is a middleware chain

func NewInChain

func NewInChain(in ...router.Constructor) InChain

NewInChain variadic constructor for inbound plugin sequence

type OutChain

type OutChain []OutLink

OutChain typed array for outbound plugin sequence

func NewOutChain

func NewOutChain(out ...OutLink) OutChain

NewOutChain variadic constructor for outbound plugin sequence

type OutLink func(req *http.Request, res *http.Response) (*http.Response, error)

OutLink interface for outbound request plugins

type Params

type Params struct {
	// StatsClient defines the stats client for tracing
	StatsClient client.Client

	// When set, the proxy will skip the TLS verification on outgoing requests.
	InsecureSkipVerify bool

	// Same as net/http.Transport.MaxIdleConnsPerHost, but the default
	// is 64. This value supports scenarios with relatively few remote
	// hosts. When the routing table contains different hosts in the
	// range of hundreds, it is recommended to set this options to a
	// lower value.
	IdleConnectionsPerHost int

	// Defines the time period of how often the idle connections are
	// forcibly closed. The default is 12 seconds. When set to less than
	// 0, the proxy doesn't force closing the idle connections.
	CloseIdleConnsPeriod time.Duration

	// The Flush interval for copying upgraded connections
	FlushInterval time.Duration

	Outbound OutChain
}

Params initialization options.

type Register

type Register struct {
	Router router.Router
	// contains filtered or unexported fields
}

Register handles the register of proxies into the chosen router. It also handles the conversion from a proxy to an http.HandlerFunc

func NewRegister

func NewRegister(router router.Router, params Params) *Register

NewRegister creates a new instance of Register

func (*Register) Add

func (p *Register) Add(route *Route) error

Add register a new route

func (*Register) AddMany

func (p *Register) AddMany(routes []*Route) error

AddMany registers many proxies at once

func (*Register) UpdateRouter

func (p *Register) UpdateRouter(router router.Router)

UpdateRouter updates the reference to the router. This is useful to reload the mux

type RoundrobinBalancer

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

RoundrobinBalancer balancer

func NewRoundrobinBalancer

func NewRoundrobinBalancer() *RoundrobinBalancer

NewRoundrobinBalancer creates a new instance of Roundrobin

func (*RoundrobinBalancer) Elect

func (b *RoundrobinBalancer) Elect(hosts []*Target) (*Target, error)

Elect backend using roundrobin strategy

type Route

type Route struct {
	Proxy    *Definition
	Inbound  InChain
	Outbound OutChain
}

Route is the container for a proxy and it's handlers

func JSONUnmarshalRoute

func JSONUnmarshalRoute(rawRoute []byte) (*Route, error)

JSONUnmarshalRoute decodes route struct from JSON

func NewRoute

func NewRoute(proxy *Definition) *Route

NewRoute creates an instance of Route

func NewRouteWithInOut

func NewRouteWithInOut(proxy *Definition, inbound InChain, outbound OutChain) *Route

NewRouteWithInOut creates an instance of Route with inbound and outbound handlers

func (*Route) AddInbound

func (r *Route) AddInbound(in ...router.Constructor)

AddInbound adds inbound middlewares

func (*Route) AddOutbound

func (r *Route) AddOutbound(out ...OutLink)

AddOutbound adds outbound middlewares

func (*Route) JSONMarshal

func (r *Route) JSONMarshal() ([]byte, error)

JSONMarshal encodes route struct to JSON

type Target

type Target struct {
	Target string `bson:"target" json:"target" valid:"url,required"`
	Weight int    `bson:"weight" json:"weight"`
}

Target is an ip address/hostname with a port that identifies an instance of a backend service

type Transport

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

Transport construct holding plugin sequences

func NewTransport

func NewTransport(statsClient client.Client, outbound OutChain) *Transport

NewTransport creates a new instance of Transport

func NewTransportWithParams

func NewTransportWithParams(o Params) *Transport

NewTransportWithParams creates a new instance of Transport with the given params

func (*Transport) RoundTrip

func (s *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error)

RoundTrip provides the Transport.RoundTrip function to handle requests the proxy receives

type Upstreams

type Upstreams struct {
	Balancing string    `bson:"balancing" json:"balancing"`
	Targets   []*Target `bson:"targets" json:"targets"`
}

Upstreams represents a collection of targets where the requests will go to

type WeightBalancer

type WeightBalancer struct{}

WeightBalancer balancer

func NewWeightBalancer

func NewWeightBalancer() *WeightBalancer

NewWeightBalancer creates a new instance of Roundrobin

func (*WeightBalancer) Elect

func (b *WeightBalancer) Elect(hosts []*Target) (*Target, error)

Elect backend using roundrobin strategy

Jump to

Keyboard shortcuts

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