Documentation
¶
Index ¶
- Variables
- func IntoHTTPMiddleware(m Middleware) func(http.Handler) http.Handler
- func IsErrMissingContextValue(err error) bool
- func IsErrUnhandled(err error) bool
- func WithContextValue(r *http.Request, key, val interface{}) *http.Request
- type ErrMissingContextValue
- type Handler
- type Middleware
- type Response
Constants ¶
This section is empty.
Variables ¶
var ErrHandled = errors.New("Error is handled and is inside the response")
ErrHandled is the error returned when an error has been translated into a response.
Functions ¶
func IntoHTTPMiddleware ¶
func IntoHTTPMiddleware(m Middleware) func(http.Handler) http.Handler
IntoHTTPMiddleware converts go-mw middleware into a net/http middleware, with one caveat: The Response input should be treated just like a ResponseWriter, i.e. modification of headers after it's handed downstream will (most likely) have no effect.
func IsErrMissingContextValue ¶
IsErrMissingContextValue returns true if the error is because of a missing context value
func IsErrUnhandled ¶
IsErrUnhandled returns true if the error is not nill and is not ErrHandled.
Types ¶
type ErrMissingContextValue ¶
type ErrMissingContextValue struct {
What string
}
ErrMissingContextValue is returned from functions which extracts data from contexts.
func (*ErrMissingContextValue) Error ¶
func (e *ErrMissingContextValue) Error() string
type Handler ¶
Handler is a function which takes in a respone and a request. Note that, in contrast to http.ResponseWriter, this handler can NOT stream data to the user.
It's not impossible to stream data, but this is the responsibility of the function writing Response into the actual http.ResponseWriter.
type Middleware ¶
Middleware is a function which takes a Handler and returns one.
func Chain ¶
func Chain(fs ...Middleware) Middleware
Chain takes an arbitrary amount of Middlewares and chains them together. The first middleware will be activated first, the second second etc.
func (Middleware) Then ¶
func (f Middleware) Then(g Middleware) Middleware
Then chains two Middleware functions and returns a new Middleware function. f will be called first, then g.
type Response ¶
type Response struct {
StatusCode int
Body interface{}
Headers http.Header
// Do not use Writer unless you really know what you're doing.
Writer http.ResponseWriter
}
A Response is the current built up response for this request. Middleware will typically set additional headers or add additional context in the http.Request.
func NewResponse ¶
func NewResponse(w http.ResponseWriter) *Response
NewResponse returns an empty Response to be used by middleware and handlers.
func (*Response) Write ¶
Write is a method which always panics. It's implemented so that users can utilize functions that works on http.ResponseWriters, which only require Header() to work as intended (e.g. http.SetCookie)
func (*Response) WriteHeader ¶
WriteHeader is a method which always panics. It's implemented so that users can utilize functions that works on http.ResponseWriters, which only require Header() to work as intended (e.g. http.SetCookie)