Documentation ¶
Overview ¶
Package app ties together application resources and handlers.
Index ¶
- Variables
- func ErrInvalidRequest(err error) render.Renderer
- func ErrRender(err error) render.Renderer
- func ErrValidation(err error, valErr validation.Errors) render.Renderer
- func LinkIDCtx(next http.Handler) http.Handler
- type API
- type DocumentResponse
- type ErrResponse
- type LinksResource
- type LinksResponse
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadRequest returns status 400 Bad Request for malformed request body. ErrBadRequest = &ErrResponse{HTTPStatusCode: http.StatusBadRequest, StatusText: http.StatusText(http.StatusBadRequest)} ErrUnauthorized = &ErrResponse{HTTPStatusCode: http.StatusUnauthorized, StatusText: http.StatusText(http.StatusUnauthorized)} // ErrForbidden returns status 403 Forbidden for unauthorized request. ErrForbidden = &ErrResponse{HTTPStatusCode: http.StatusForbidden, StatusText: http.StatusText(http.StatusForbidden)} // ErrNotFound returns status 404 Not Found for invalid resource request. ErrNotFound = &ErrResponse{HTTPStatusCode: http.StatusNotFound, StatusText: http.StatusText(http.StatusNotFound)} // ErrInternalServerError returns status 500 Internal Server Error. ErrInternalServerError = &ErrResponse{HTTPStatusCode: http.StatusInternalServerError, StatusText: http.StatusText(http.StatusInternalServerError)} )
Functions ¶
func ErrInvalidRequest ¶
ErrInvalidRequest returns status 422 Unprocessable Entity including error message.
func ErrValidation ¶
func ErrValidation(err error, valErr validation.Errors) render.Renderer
ErrValidation returns status 422 Unprocessable Entity stating validation errors.
Types ¶
type API ¶
type API struct {
Links *LinksResource
}
API provides application resources and handlers.
type DocumentResponse ¶
DocumentResponse is the response payload for the Document data model.
In the DocumentResponse object, first a Render() is called on itself, then the next field, and so on, all the way down the tree. Render is called in top-down order, like a http handler middleware chain.
type ErrResponse ¶
type ErrResponse struct { Err error `json:"-"` // low-level runtime error HTTPStatusCode int `json:"-"` // http response status code StatusText string `json:"status"` // user-level status message AppCode int64 `json:"code,omitempty"` // application-specific error code ErrorText string `json:"error,omitempty"` // application-level error message, for debugging ValidationErrors validation.Errors `json:"errors,omitempty"` // user level model validation errors }
ErrResponse renderer type for handling all sorts of errors.
func (*ErrResponse) Render ¶
func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error
Render sets the application-specific error code in AppCode.
type LinksResource ¶
type LinksResource struct { }
LinksResource implements links controller handler.
func NewLinksResource ¶
func NewLinksResource() *LinksResource
NewLinksResource creates and returns a links resource.
type LinksResponse ¶
LinksResponse is the response payload for the Document data model.
In the DocumentResponse object, first a Render() is called on itself, then the next field, and so on, all the way down the tree. Render is called in top-down order, like a http handler middleware chain.