Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InvokeHandler ¶
func InvokeHandler(h Handler, method, path string, w http.ResponseWriter, r *http.Request, tx *sqlx.Tx, renderer ResponseRenderer) error
InvokeHandler invokes the handler given. This test should be used in unit tests only.
func NewHttpHandler ¶
Types ¶
type ChainHandler ¶
type ChainHandler interface { Handler // Then creates a new handler adds all handlers from this // chain and the handler provided. Then(h Handler) ChainHandler }
ChainHandler extends Handler and is used by Chain() to allow for incrementally building chained handlers.
func Chain ¶
func Chain(handlers ...Handler) ChainHandler
Chain creates a handler that executes the handlers in sequence. If a handler returns an error or writes any bytes to the http.ResponseWriter, the chain is broken and no more handlers are processed.
type Handler ¶
type Handler interface { // Handle handles a HTTP request and returns an error if the operation fails. The implementor // is responsible for writing the error to the response. Handle(tx *sqlx.Tx, renderer ResponseRenderer, w http.ResponseWriter, r *http.Request) error }
type HttpError ¶
HttpError is an interface for errors that are transferable over HTTP as JSON.
func EncapulateIfError ¶
EncapulateIfError encapsulates the error provided as a HttpError if not nil. If the error provided is nil, this function returns nil.
func NewHttpError ¶
NewHttpError returns an encapsulated error suitable for JSON serialization. The error also has a HTTP status code for usability.
func ReadInt64ID ¶
ReadInt64ID returns an int64 ID read from the mux vars (URL vars). vars is generated from a request by using 'mux.Vars(r)'. If the operation fails a HttpError with status code http.StatusBadRequest is returned.
type MockResponseRenderer ¶
func (*MockResponseRenderer) WriteEmpty ¶
func (_m *MockResponseRenderer) WriteEmpty(w http.ResponseWriter, statusCode int)
WriteEmpty provides a mock function with given fields: w, statusCode
func (*MockResponseRenderer) WriteError ¶
func (_m *MockResponseRenderer) WriteError(w http.ResponseWriter, err error)
WriteError provides a mock function with given fields: w, err
func (*MockResponseRenderer) WriteObject ¶
func (_m *MockResponseRenderer) WriteObject(w http.ResponseWriter, statusCode int, val interface{})
WriteObject provides a mock function with given fields: w, statusCode, val
type ResponseRenderer ¶
type ResponseRenderer interface { WriteEmpty(w http.ResponseWriter, statusCode int) WriteObject(w http.ResponseWriter, statusCode int, val interface{}) WriteError(w http.ResponseWriter, err error) }
func NewJSONResponseRenderer ¶
func NewJSONResponseRenderer() ResponseRenderer
NewJSONResponseRenderer creates a renderer that outputs JSON.