routing

package
v0.0.0-...-3aae161 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Configuration = []Config{
	Config{
		Path:     "/anything/standard",
		Upstream: upstreams.HTTPBin,
	},
	Config{
		Path:     "/anything/(?:foo|bar)$",
		Upstream: upstreams.HTTPBin,
	},
	Config{
		Path:     "/(?P<start>anything)/(?P<cap>foobar)$",
		Upstream: upstreams.HTTPBin,
		Override: Override{
			Header:     "X-BF-Testing",
			Match:      "integralist",
			ModifyPath: "/anything/newthing${cap}",
		},
	},
	Config{
		Path:       "/(?P<cap>double-checks)$",
		Upstream:   upstreams.HTTPBin,
		ModifyPath: "/anything/toplevel-modified-${cap}",
		Override: Override{
			Header:     "X-BF-Testing",
			Match:      "integralist",
			ModifyPath: "/anything/override-modified-${cap}",
		},
	},
	Config{
		Path:     "/anything/(?P<cap>integralist)",
		Upstream: upstreams.HTTPBin,
		Override: Override{
			Header:     "X-BF-Testing",
			Match:      "integralist",
			ModifyPath: "/about",
			Upstream:   upstreams.Integralist,
		},
	},
	Config{
		Path:     "/about",
		Upstream: upstreams.HTTPBin,
		Override: Override{
			Query:    "s",
			Match:    "integralist",
			Upstream: upstreams.Integralist,
		},
	},
	Config{
		Path:     "/anything/querytest",
		Upstream: upstreams.HTTPBin,
		Override: Override{
			Query:      "s",
			Match:      `integralist(?P<cap>\d{1,3})$`,
			MatchType:  "regex",
			ModifyPath: "/anything/newthing${cap}",
		},
	},
	Config{
		Path:       `/(?P<cap>foo\w{3})`,
		Upstream:   upstreams.HTTPBin,
		ModifyPath: "/anything/${cap}",
	},
	Config{
		Path:       "/beep(?P<cap>boop)",
		Upstream:   upstreams.HTTPBin,
		ModifyPath: "/anything/beepboop",
	},
}

Configuration is the main routing logic that dictates how routing behaviours should be controlled and overriding behaviours determined.

Functions

This section is empty.

Types

type Config

type Config struct {
	Path       string
	Upstream   *upstreams.Upstream
	ModifyPath string
	Override   Override
}

Config defines the expected top level routing configuration

type Handler

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

Handler defines our own custom HTTP handler that supports pattern matching a path using regular expressions

func (*Handler) HandleFunc

func (h *Handler) HandleFunc(config Config, handler func(http.ResponseWriter, *http.Request))

HandleFunc appends a new route and coerces the given function into a HandlerFunc MustCompile allows this service to fail fast when provided invalid regex config

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP attempts to match the incoming request path against the configured route patterns we've defined, and if a match is found we take any named capture groups and add them onto the request's query so we can later interpolate the captured values back into the request path (if configured to be used there -- see README for examples). Before the response is sent back to the client we clean-up the added query parameters.

type Override

type Override struct {
	Header     string
	Query      string
	Match      string
	MatchType  string
	Upstream   *upstreams.Upstream
	ModifyPath string
}

Override defines the expected sub level routing override configuration

Jump to

Keyboard shortcuts

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