Version: v0.0.0-...-4deb780 Latest Latest

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 22 Imported by: 68




This section is empty.


This section is empty.


func NewBalancedReverseProxy

func NewBalancedReverseProxy(def *Definition, balancer balancer.Balancer, statsClient client.Client) *httputil.ReverseProxy

NewBalancedReverseProxy creates a reverse proxy that is load balanced


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"`
	Methods            []string           `bson:"methods" json:"methods"`
	Hosts              []string           `bson:"hosts" json:"hosts"`
	ForwardingTimeouts ForwardingTimeouts `bson:"forwarding_timeouts" json:"forwarding_timeouts" mapstructure:"forwarding_timeouts"`

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 Duration

type Duration time.Duration

Duration is the time.Duration that can be unmarshalled from JSON

func (Duration) GetBSON

func (d Duration) GetBSON() (interface{}, error)

GetBSON implements marshalling to BSON

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements marshalling from JSON

func (*Duration) SetBSON

func (d *Duration) SetBSON(raw bson.RawValue) error

SetBSON implements unmarshalling from BSON

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements unmarshalling from JSON

type ForwardingTimeouts

type ForwardingTimeouts struct {
	DialTimeout           Duration `bson:"dial_timeout" json:"dial_timeout"`
	ResponseHeaderTimeout Duration `bson:"response_header_timeout" json:"response_header_timeout"`

ForwardingTimeouts contains timeout configurations for forwarding requests to the backend servers.

type Register

type Register struct {
	// 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(opts ...RegisterOption) *Register

NewRegister creates a new instance of Register

func (*Register) Add

func (p *Register) Add(definition *RouterDefinition) error

Add register a new route

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 RegisterOption

type RegisterOption func(*Register)

RegisterOption represents the register options

func WithFlushInterval

func WithFlushInterval(d time.Duration) RegisterOption

WithFlushInterval sets the Flush interval for copying upgraded connections

func WithIdleConnPurgeTicker

func WithIdleConnPurgeTicker(d time.Duration) RegisterOption

WithIdleConnPurgeTicker purges idle connections on every interval if set this is done to prevent permanent keep-alive on connections with high ops

func WithIdleConnTimeout

func WithIdleConnTimeout(d time.Duration) RegisterOption

WithIdleConnTimeout sets the maximum amount of time an idle (keep-alive) connection will remain idle before closing itself.

func WithIdleConnectionsPerHost

func WithIdleConnectionsPerHost(value int) RegisterOption

WithIdleConnectionsPerHost sets idle connections per host option

func WithIsPublicEndpoint

func WithIsPublicEndpoint(b bool) RegisterOption

WithIsPublicEndpoint adds trace metadata from incoming requests as parent span if set to false

func WithRouter

func WithRouter(router router.Router) RegisterOption

WithRouter sets the router

func WithStatsClient

func WithStatsClient(statsClient client.Client) RegisterOption

WithStatsClient sets stats client instance for proxy

type RouterDefinition

type RouterDefinition struct {
	// contains filtered or unexported fields

RouterDefinition represents an API that you want to proxy with internal router routines

func NewRouterDefinition

func NewRouterDefinition(def *Definition) *RouterDefinition

NewRouterDefinition creates a new Proxy RouterDefinition from Proxy Definition

func (*RouterDefinition) AddMiddleware

func (d *RouterDefinition) AddMiddleware(m router.Constructor)

AddMiddleware adds a middleware to a site's middleware stack.

func (*RouterDefinition) Middleware

func (d *RouterDefinition) Middleware() []router.Constructor

Middleware returns s.middleware (useful for tests).

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 Targets

type Targets []*Target

Targets is a set of target

func (Targets) ToBalancerTargets

func (t Targets) ToBalancerTargets() []*balancer.Target

ToBalancerTargets returns the balancer expected type

type Upstreams

type Upstreams struct {
	Balancing string  `bson:"balancing" json:"balancing"`
	Targets   Targets `bson:"targets" json:"targets"`

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


Path Synopsis
Package balancer provides a simple interface to create concrete balancer algorightms that can be used to choose an upstream
Package balancer provides a simple interface to create concrete balancer algorightms that can be used to choose an upstream

Jump to

Keyboard shortcuts

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