mux

package
v0.0.0-...-7f749bc Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package mux provides some basic implementations for building routers based on net/http mux

Index

Constants

View Source
const DefaultDebugPattern = "/__debug/"

DefaultDebugPattern is the default pattern used to define the debug endpoint

Variables

EndpointHandler is a HandlerFactory that adapts the mux router with the injected proxy and the default RequestBuilder

View Source
var ErrInternalError = errors.New("internal server error")

ErrInternalError is the error returned by the router when something went wrong

View Source
var NewRequest = NewRequestBuilder(func(r *http.Request) map[string]string {
	return map[string]string{}
})

NewRequest is a RequestBuilder that creates a proxy request from the received http request without processing the uri params

Functions

func DebugHandler

func DebugHandler(logger logging.Logger) http.HandlerFunc

DebugHandler creates a dummy handler function, useful for quick integration tests

func DefaultEngine

func DefaultEngine() *http.ServeMux

DefaultEngine returns a new engine using the http.ServeMux router

func DefaultFactory

func DefaultFactory(pf proxy.Factory, logger logging.Logger) router.Factory

DefaultFactory returns a net/http mux router factory with the injected proxy factory and logger

func NewFactory

func NewFactory(cfg Config) router.Factory

NewFactory returns a net/http mux router factory with the injected configuration

Types

type Config

type Config struct {
	Engine         Engine
	Middlewares    []HandlerMiddleware
	HandlerFactory HandlerFactory
	ProxyFactory   proxy.Factory
	Logger         logging.Logger
	DebugPattern   string
}

Config is the struct that collects the parts the router should be builded from

type Engine

type Engine interface {
	http.Handler
	Handle(pattern string, handler http.Handler)
}

Engine defines the minimun required interface for the mux compatible engine

type HandlerFactory

type HandlerFactory func(*config.EndpointConfig, proxy.Proxy) http.HandlerFunc

HandlerFactory creates a handler function that adapts the mux router with the injected proxy

func CustomEndpointHandler

func CustomEndpointHandler(rb RequestBuilder) HandlerFactory

CustomEndpointHandler returns a HandlerFactory with the received RequestBuilder

type HandlerMiddleware

type HandlerMiddleware interface {
	Handler(h http.Handler) http.Handler
}

HandlerMiddleware is the interface for the decorators over the http.Handler

type ParamExtractor

type ParamExtractor func(r *http.Request) map[string]string

ParamExtractor is a function that extracts thes query params from the requested uri

type RequestBuilder

type RequestBuilder func(r *http.Request, queryString []string) *proxy.Request

RequestBuilder is a function that creates a proxy.Request from the received http request

func NewRequestBuilder

func NewRequestBuilder(paramExtractor ParamExtractor) RequestBuilder

NewRequestBuilder gets a RequestBuilder with the received ParamExtractor as a query param extraction mecanism

Jump to

Keyboard shortcuts

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