mux

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

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

View Source
const DefaultDebugPattern = "/__debug/"

DefaultDebugPattern is the default pattern used to define the debug endpoint

View Source
const NEGOTIATE = "negotiate"

NEGOTIATE defines the value of the OutputEncoding for the negotiated render

Variables

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

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

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 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

func NewFactory(cfg Config) router.Factory

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

func NoopParamExtractor added in v1.0.0

func NoopParamExtractor(_ *http.Request) map[string]string

NoopParamExtractor is a No Op ParamExtractor (returns an empty map of params)

func RegisterRender

func RegisterRender(name string, r Render)

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 Engine

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

Engine defines the minimun required interface for the mux compatible engine

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

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 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

type RequestBuilder func(r *http.Request, queryString, headersToSend []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 mechanism

type RunServerFunc

type RunServerFunc func(context.Context, config.ServiceConfig, http.Handler) error

RunServerFunc is a func that will run the http Server with the given params.

Jump to

Keyboard shortcuts

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