Documentation ¶
Overview ¶
Package muxhttp provides mux, middleware, handler with regards to routing capabilities
Index ¶
Constants ¶
const KeyValues ctxKey = 1
KeyValues is how request values or stored/retrieved.
Variables ¶
This section is empty.
Functions ¶
func IsShutdown ¶
IsShutdown checks to see if the shutdown error is contained in the specified error value.
func NewRequestError ¶
NewRequestError wraps a provided error with an HTTP status code. This function should be used when service encounter expected errors.
func NewShutdownError ¶
NewShutdownError returns an error that causes the framework to signal a graceful shutdown.
Types ¶
type ErrorRequest ¶
type ErrorRequest struct { Err error Status int Fields []FieldError }
ErrorRequest is used to pass an error during the request through the application with web specific context.
func (*ErrorRequest) Error ¶
func (err *ErrorRequest) Error() string
ErrorField implements the error interface. It uses the default message of the wrapped error. This is what will be shown in the services' logs.
type ErrorResponse ¶
type ErrorResponse struct { Error string `json:"error"` Fields []FieldError `json:"fields,omitempty"` }
ErrorResponse is the form used for API responses from failures in the API.
type FieldError ¶
FieldError is used to indicate an error with a specific request field.
type Middleware ¶
Middleware is a function designed to run some code before and/or after another Handler. It is designed to remove boilerplate or other concerns not direct to any given Handler.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is the entrypoint into our application and what controls the context of each request. Feel free to add any configuration data/logic on this type.
func NewRouter ¶
NewRouter constructs an Router to handle a set of routes. Any Middleware provided will be ran for every request.
func (*Router) Handle ¶
func (a *Router) Handle(method, url string, h Handler, mw ...Middleware)
Handle associates a handler function with an HTTP Method and URL pattern.
It converts our custom handler type to the std lib Handler type. It captures errors from the handler and serves them to the cli in a uniform way.
func (*Router) ServeHTTP ¶
func (a *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface.
func (*Router) SignalShutdown ¶
func (a *Router) SignalShutdown()
SignalShutdown is used to gracefully shutdown the appserver when an integrity issue is identified.