Documentation ¶
Index ¶
- Constants
- func JSON(w http.ResponseWriter, resp Response) error
- func Render(w http.ResponseWriter, resp Response) error
- type ClientError
- type Reason
- type Response
- func NewBadRequest(msg string) Response
- func NewDBFailure(err error) Response
- func NewForbidden(msg string) Response
- func NewInternalError(msg string) Response
- func NewNoContent() Response
- func NewNotFound() Response
- func NewResponse() Response
- func NewTooManyRequests(msg string) Response
- func NewUnauthorized(msg string) Response
- func NewUnauthorizedBasic(r *Reason) Response
- func NewUnprocessable(r *Reason) Response
Constants ¶
const ( // CodeMissing means a resource does not exist CodeMissing = "missing" // CodeMissingField means a required field on a resource has not been set. CodeMissingField = "missing_field" // CodeInvalid means the formatting of a field is invalid CodeInvalid = "invalid" // CodeAlreadyExists means another resource has the same value as this field. CodeAlreadyExists = "already_exists" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClientError ¶
type ClientError struct { Message string `json:"message"` Reason *Reason `json:"error,omitempty"` // Integrate Stripe errors Code string `json:"code,omitempty"` // For some errors that could be handled programmatically, a short string indicating the error code reported. Param string `json:"param,omitempty"` // If the error is parameter-specific, the parameter related to the error. For example, you can use this to display a message near the correct form field. Type string `json:"type,omitempty"` // The type of error returned. One of api_connection_error, api_error, authentication_error, card_error, idempotency_error, invalid_request_error, or rate_limit_error }
ClientError respond to 4xx http status.
type Reason ¶
type Reason struct { Message string `json:"-"` Field string `json:"field"` Code string `json:"code"` // contains filtered or unexported fields }
Reason tells why its unprocessable. Mostly used for validation errors.
func NewInvalid ¶ added in v0.0.18
NewInvalid creates a new instance of invalid reason.
func (*Reason) GetMessage ¶
GetMessage returns Reason's descriptive message.
func (*Reason) SetMessage ¶
SetMessage set the message to be carried away.
type Response ¶
Response collects all data needed for an HTTP response
func NewBadRequest ¶
NewBadRequest creates a new Response for 400 Bad Request with the specified msg
func NewDBFailure ¶
NewDBFailure handles various errors returned from the model layter MySQL duplicate error when inerting into uniquely constraint column; ErrNoRows if it cannot retrieve any rows of the specified criteria; `field` is used to identify which field is causing duplicate error.
func NewInternalError ¶
NewInternalError creates response for internal server error
func NewNoContent ¶
func NewNoContent() Response
NewNoContent creates an HTTP 204 No Content response
func NewResponse ¶
func NewResponse() Response
NewResponse creates a new instance of Response with default values
func NewTooManyRequests ¶ added in v0.0.5
NewTooManyRequests respond to rate limit.
func NewUnauthorized ¶
NewUnauthorized create a new instance of Response for 401 Unauthorized response
func NewUnauthorizedBasic ¶ added in v0.0.17
NewUnauthorizedBasic creates a new instance of Response for 401 Unauthorized with WWW-Authenticate header.
func NewUnprocessable ¶
NewUnprocessable creates response 422 Unprocessable Entity