Documentation ¶
Overview ¶
Package mux provides some basic implementations for building routers based on net/http mux
Index ¶
- Constants
- Variables
- func DebugHandler(logger logging.Logger) http.HandlerFunc
- func DefaultFactory(pf proxy.Factory, logger logging.Logger) router.Factory
- func EchoHandler() http.HandlerFunc
- func HealthHandler(w http.ResponseWriter, _ *http.Request)
- func NewFactory(cfg Config) router.Factory
- func NoopParamExtractor(_ *http.Request) map[string]string
- func RegisterRender(name string, r Render)
- type BasicEngine
- type Config
- type Engine
- type HTTPErrorInterceptor
- type HandlerFactory
- type HandlerMiddleware
- type ParamExtractor
- type Render
- type RequestBuilder
- type RunServerFunc
Constants ¶
const ( DefaultDebugPattern = "/__debug/" DefaultEchoPattern = "/__echo/" )
DefaultDebugPattern is the default pattern used to define the debug endpoint
const NEGOTIATE = "negotiate"
NEGOTIATE defines the value of the OutputEncoding for the negotiated render
Variables ¶
var EndpointHandler = CustomEndpointHandler(NewRequest)
EndpointHandler is a HandlerFactory that adapts the mux router with the injected proxy and the default RequestBuilder
var NewRequest = NewRequestBuilder(NoopParamExtractor)
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 DefaultFactory ¶
DefaultFactory returns a net/http mux router factory with the injected proxy factory and logger
func EchoHandler ¶ added in v2.2.5
func EchoHandler() http.HandlerFunc
EchoHandler creates a dummy handler function, useful for quick integration tests
func HealthHandler ¶
func HealthHandler(w http.ResponseWriter, _ *http.Request)
HealthHandler is a dummy http.HandlerFunc implementation for exposing a health check endpoint
func NewFactory ¶
NewFactory returns a net/http mux router factory with the injected configuration
func NoopParamExtractor ¶
NoopParamExtractor is a No Op ParamExtractor (returns an empty map of params)
func RegisterRender ¶
RegisterRender allows clients to register their custom renders
Types ¶
type BasicEngine ¶ added in v2.0.2
type BasicEngine struct {
// contains filtered or unexported fields
}
BasicEngine is a slightly customized http.ServeMux router
func DefaultEngine ¶
func DefaultEngine() *BasicEngine
DefaultEngine returns a new engine using BasicEngine
func (*BasicEngine) Handle ¶ added in v2.0.2
func (e *BasicEngine) Handle(pattern, method string, handler http.Handler)
Handle registers a handler at a given url pattern and http method
func (*BasicEngine) ServeHTTP ¶ added in v2.0.2
func (e *BasicEngine) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP adds a error interceptor and delegates the request dispatching to the internal request multiplexer.
type Config ¶
type Config struct { Engine Engine Middlewares []HandlerMiddleware HandlerFactory HandlerFactory ProxyFactory proxy.Factory Logger logging.Logger DebugPattern string EchoPattern string RunServer RunServerFunc }
Config is the struct that collects the parts the router should be builded from
type HTTPErrorInterceptor ¶
type HTTPErrorInterceptor struct { http.ResponseWriter // contains filtered or unexported fields }
HTTPErrorInterceptor is a reposnse writer that adds a header signaling incomplete response in case of seeing a status code not equal to 200
func NewHTTPErrorInterceptor ¶
func NewHTTPErrorInterceptor(w http.ResponseWriter) *HTTPErrorInterceptor
NewHTTPErrorInterceptor returns a HTTPErrorInterceptor over theinjected response writer
func (*HTTPErrorInterceptor) WriteHeader ¶
func (i *HTTPErrorInterceptor) WriteHeader(code int)
WriteHeader records the status code and adds a header signaling incomplete responses
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 using the default ToHTTPError function
func CustomEndpointHandlerWithHTTPError ¶
func CustomEndpointHandlerWithHTTPError(rb RequestBuilder, errF server.ToHTTPError) HandlerFactory
CustomEndpointHandlerWithHTTPError returns a HandlerFactory with the received RequestBuilder
type HandlerMiddleware ¶
HandlerMiddleware is the interface for the decorators over the http.Handler
type ParamExtractor ¶
ParamExtractor is a function that extracts query params from the requested uri
type Render ¶
type Render func(http.ResponseWriter, *proxy.Response)
Render defines the signature of the functions to be use for the final response encoding and rendering
type RequestBuilder ¶
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 mechanism
type RunServerFunc ¶
RunServerFunc is a func that will run the http Server with the given params.