route

package
v0.0.0-...-0f3e1e6 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2017 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const Commands = `` /* 1551-byte string literal not displayed */

Variables

View Source
var Matcher = map[string]matcher{
	"prefix": prefixMatcher,
	"glob":   globMatcher,
}

Matcher contains the available matcher functions. Update config/load.go#load after updating.

View Source
var Picker = map[string]picker{
	"rnd": rndPicker,
	"rr":  rrPicker,
}

Picker contains the available picker functions. Update config/load.go#load after updating.

View Source
var ServiceRegistry metrics.Registry = metrics.NoopRegistry{}

ServiceRegistry stores the metrics for the services.

Functions

func SetTable

func SetTable(t Table)

SetTable sets the active routing table. A nil value logs a warning and is ignored. The function is safe to be called from multiple goroutines.

Types

type Cmd

type Cmd string
const (
	RouteAddCmd    Cmd = "route add"
	RouteDelCmd    Cmd = "route del"
	RouteWeightCmd Cmd = "route weight"
)

type Route

type Route struct {
	// Host contains the host of the route.
	// not used for routing but for config generation
	// Table has a map with the host as key
	// for faster lookup and smaller search space.
	Host string

	// Path is the path prefix from a request uri
	Path string

	// Opts is the raw route options
	Opts map[string]string

	// Targets contains the list of URLs
	Targets []*Target
	// contains filtered or unexported fields
}

Route maps a path prefix to one or more target URLs. routes can have a weight value which describes the amount of traffic this route should get. You can specify that a route should get a fixed percentage of the traffic independent of how many instances are running.

func (*Route) TargetConfig

func (r *Route) TargetConfig(t *Target, addWeight bool) string

type RouteDef

type RouteDef struct {
	Cmd     Cmd               `json:"cmd"`
	Service string            `json:"service"`
	Src     string            `json:"src"`
	Dst     string            `json:"dst"`
	Weight  float64           `json:"weight"`
	Tags    []string          `json:"tags,omitempty"`
	Opts    map[string]string `json:"opts,omitempty"`
}

func Parse

func Parse(in string) (defs []*RouteDef, err error)

Parse loads a routing table from a set of route commands.

The commands are parsed in order and order matters. Deleting a route that has not been created yet yields a different result than the other way around.

type Routes

type Routes []*Route

Routes stores a list of routes usually for a single host.

func (Routes) Len

func (rt Routes) Len() int

sort by path in reverse order (most to least specific)

func (Routes) Less

func (rt Routes) Less(i, j int) bool

func (Routes) Swap

func (rt Routes) Swap(i, j int)

type Table

type Table map[string]Routes

Table contains a set of routes grouped by host. The host routes are sorted from most to least specific by sorting the routes in reverse order by path.

func GetTable

func GetTable() Table

GetTable returns the active routing table. The function is safe to be called from multiple goroutines and the value is never nil.

func NewTable

func NewTable(s string) (t Table, err error)

func (Table) Dump

func (t Table) Dump() string

Dump returns the routing table as a detailed

func (Table) Lookup

func (t Table) Lookup(req *http.Request, trace string, pick picker, match matcher) (target *Target)

Lookup finds a target url based on the current matcher and picker or nil if there is none. It first checks the routes for the host and if none matches then it falls back to generic routes without a host. This is useful for a catch-all '/' rule.

func (Table) LookupHost

func (t Table) LookupHost(host string, pick picker) *Target

func (Table) String

func (t Table) String() string

String returns the routing table as config file which can be read by Parse() again.

type Target

type Target struct {
	// Service is the name of the service the targetURL points to
	Service string

	// Tags are the list of tags for this target
	Tags []string

	// StripPath will be removed from the front of the outgoing
	// request path
	StripPath string

	// TLSSkipVerify disables certificate validation for upstream
	// TLS connections.
	TLSSkipVerify bool

	// Host signifies what the proxy will set the Host header to.
	// The proxy does not modify the Host header by default.
	// When Host is set to 'dst' the proxy will use the host name
	// of the target host for the outgoing request.
	Host string

	// URL is the endpoint the service instance listens on
	URL *url.URL

	// FixedWeight is the weight assigned to this target.
	// If the value is 0 the targets weight is dynamic.
	FixedWeight float64

	// Weight is the actual weight for this service in percent.
	Weight float64

	// Timer measures throughput and latency of this target
	Timer metrics.Timer

	// AuthEnabled indicates whether the target has authentication/authorization
	// enabled
	AuthEnabled bool
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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