Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInternalServerError = &ErrResponse{ HTTPStatusCode: http.StatusInternalServerError, StatusText: http.StatusText(http.StatusInternalServerError), } ErrForbidden = &ErrResponse{ HTTPStatusCode: http.StatusForbidden, StatusText: http.StatusText(http.StatusForbidden), } )
The list of default error types without specific error message.
var ErrAPIUnsupported = errors.New("unsupported api version")
ErrAPIUnsupported an unsupported api version
var ErrMissingAPIVersion = errors.New("missing api version header")
ErrMissingAPIVersion a missing api version header with the version text.
var ErrMissingToken = errors.New("missing authorization header")
ErrMissingToken a missing authorization header with the Bearer token.
Functions ¶
func ErrInvalidRequest ¶
ErrInvalidRequest returns status 422 Unprocessable Entity including error message.
func ErrURLNotFound ¶
ErrURLNotFound returns status 404 Not Found including error message.
func ErrUnauthorized ¶
ErrUnauthorized renders status 401 Unauthorized with custom error message.
Types ¶
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 }
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 Resource ¶
Resource defines dependencies for url handlers.
func NewResource ¶
NewResource returns a configures url resource.
func (Resource) HandleShortenURL ¶
func (rs Resource) HandleShortenURL(w http.ResponseWriter, r *http.Request)
HandleShortenURL shortens the url and returns the shrotened url in the response body