Documentation ¶
Overview ¶
Package http provides common structures and functions for HTTP controllers.
Index ¶
- func DecodingError(w http.ResponseWriter)
- func ErrorJSON(w http.ResponseWriter, error string, code int)
- func HandleError(err error, fn func(e *usecase.Error))
- func InternalServerError(w http.ResponseWriter)
- func MethodNotAllowed(w http.ResponseWriter, r *http.Request)
- func NotFound(w http.ResponseWriter, r *http.Request)
- func UnsupportedMediaType(w http.ResponseWriter, r *http.Request, contentTypes []string)
- type Middleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodingError ¶
func DecodingError(w http.ResponseWriter)
DecodingError writes DecodingError to response.
func ErrorJSON ¶
func ErrorJSON(w http.ResponseWriter, error string, code int)
ErrorJSON writes error in JSON format and status code to response.
func HandleError ¶
HandleError calls fn or panics if error is internal.
func InternalServerError ¶
func InternalServerError(w http.ResponseWriter)
InternalServerError writes InternalServerError to response.
func MethodNotAllowed ¶
func MethodNotAllowed(w http.ResponseWriter, r *http.Request)
MethodNotAllowed writes MethodNotAllowed error to response.
func NotFound ¶
func NotFound(w http.ResponseWriter, r *http.Request)
NotFound writes NotFound error to response.
func UnsupportedMediaType ¶
func UnsupportedMediaType(w http.ResponseWriter, r *http.Request, contentTypes []string)
UnsupportedMediaType writes UnsupportedMediaType error to response.
Types ¶
type Middleware ¶
Middleware is function that takes and returns http.Handler. It performs some function on request or response at specific stage in HTTP pipeline.
func ContentTypeMiddleware ¶
func ContentTypeMiddleware(contentTypes ...string) Middleware
ContentTypeMiddleware creates a middleware verifying that Content-Type header has an allowed value. It returns Middleware instance.
func LoggerMiddleware ¶
func LoggerMiddleware(logger log.Logger) Middleware
LoggerMiddleware creates a middleware that logs each request. It returns Middleware instance.
func RecovererMiddleware ¶
func RecovererMiddleware(logger log.Logger) Middleware
RecovererMiddleware creates a middleware that handles panics and logs them. It returns Middleware instance.