Documentation ¶
Overview ¶
Package mux provides some basic implementations for building routers based on net/http mux
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 DefaultEngine() *engine
- func DefaultFactory(pf proxy.Factory, logger logging.Logger) router.Factory
- func HealthHandler(w http.ResponseWriter, r *http.Request)
- func NewFactory(cfg Config) router.Factory
- func NoopParamExtractor(_ *http.Request) map[string]string
- func RegisterRender(name string, r Render)
- type Config
- type Engine
- type HTTPErrorInterceptor
- type HandlerFactory
- type HandlerMiddleware
- type ParamExtractor
- type Render
- type RequestBuilder
- type RunServerFunc
Constants ¶
const DefaultDebugPattern = "/__debug/"
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 DefaultEngine ¶
func DefaultEngine() *engine
DefaultEngine returns a new engine using a slightly customized http.ServeMux router
func DefaultFactory ¶
DefaultFactory returns a net/http mux router factory with the injected proxy factory and logger
func HealthHandler ¶ added in v1.2.0
func HealthHandler(w http.ResponseWriter, r *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 ¶ added in v1.0.0
NoopParamExtractor is a No Op ParamExtractor (returns an empty map of params)
func RegisterRender ¶
RegisterRender allows clients to register their custom renders
Types ¶
type Config ¶
type Config struct { Engine Engine Middlewares []HandlerMiddleware HandlerFactory HandlerFactory ProxyFactory proxy.Factory Logger logging.Logger DebugPattern 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 router.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.