Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 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 ¶
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.