proxy

package
v0.0.0-...-43548f9 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2017 License: MIT Imports: 12 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

This section is empty.

Functions

This section is empty.

Types

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"`
	UpstreamURL         string   `bson:"upstream_url" json:"upstream_url" mapstructure:"upstream_url" valid:"url,required"`
	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) 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 stats.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

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 Transport

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

Transport construct holding plugin sequences

func NewTransport

func NewTransport(statsClient stats.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

Jump to

Keyboard shortcuts

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