Documentation ¶
Index ¶
- Variables
- func AcceptHandler(next http.Handler) http.Handler
- func Body(r *http.Request) interface{}
- func BodyHandler(v interface{}) func(http.Handler) http.Handler
- func ContentTypeHandler(next http.Handler) http.Handler
- func Error(w http.ResponseWriter, err *Err)
- func LoggingHandler(next http.Handler) http.Handler
- func New() *mux.Mux
- func RecoverHandler(next http.Handler) http.Handler
- func Write(w http.ResponseWriter, v interface{})
- type Err
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrBadRequest = &Err{"bad_request", 400, "Bad request", "Request body is not well-formed. It must be JSON."} ErrNotFound = &Err{"not_found", 404, "Not found", "Route not found."} ErrNotAcceptable = &Err{"not_acceptable", 406, "Not acceptable", "Accept HTTP header must be \"application/vnd.api+json\"."} ErrUnsupportedMediaType = &Err{"unsupported_media_type", 415, "Unsupported Media Type", "Content-Type header must be \"application/vnd.api+json\"."} ErrInternalServer = &Err{"internal_server_error", 500, "Internal Server Error", "Something went wrong."} )
Functions ¶
func AcceptHandler ¶
Returns an error if the Accept HTTP header is not "application/vnd.api+json".
func BodyHandler ¶
Decodes a request body into the struct passed to the middleware. If the request body is not JSON, it will return a 400 Bad Request error. Stores the decoded body into a context object.
func ContentTypeHandler ¶
Returns an error if the Content-Type HTTP header is not "application/vnd.api+json".
func Error ¶
func Error(w http.ResponseWriter, err *Err)
Encodes the error into JSON, sets the adequate Content-Type HTTP header and set the status code related to the error.
func RecoverHandler ¶
If the code panics, it logs the error and returns a 500 Internal Server Error error.
func Write ¶
func Write(w http.ResponseWriter, v interface{})
Encodes the response into JSON and sets the adequate Content-Type HTTP header.
Types ¶
Click to show internal directories.
Click to hide internal directories.