Documentation ¶
Index ¶
- Variables
- func FromRequest(r *http.Request, destination interface{}) error
- func ToValues(source interface{}) url.Values
- func Validate(request Request, params ...interface{}) error
- func Write(w http.ResponseWriter, response Response) error
- type ErrorResponse
- type Request
- type Response
- type SpecialValuesConvertable
- type SuccessResponse
Constants ¶
This section is empty.
Variables ¶
var ( // InternalServerError is an error response InternalServerError = &ErrorResponse{Code: "internal_server_error", Message: "Internal Server Error, please try again.", Status: http.StatusInternalServerError} // InvalidParameterError is an error response InvalidParameterError = &ErrorResponse{Code: "invalid_parameter", Message: "Invalid parameter.", Status: http.StatusBadRequest} )
Functions ¶
func FromRequest ¶
FromRequest will populate destination fields using http.Request post values.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct { // HTTP status code Status int `json:"-"` // Error status code Code string `json:"code"` // Error message that will be returned to API consumer Message string `json:"message"` // Additional information returned to API consumer MoreInfo string `json:"more_info,omitempty"` // Error data that will be returned to API consumer Data map[string]interface{} `json:"data,omitempty"` }
ErrorResponse represents error response and implements server.Response and error interfaces
func NewInvalidParameterError ¶
func NewInvalidParameterError(name, moreInfo string) *ErrorResponse
NewInvalidParameterError creates and returns a new InvalidParameterError
func NewMissingParameter ¶
func NewMissingParameter(name string) *ErrorResponse
NewMissingParameter creates and returns a new missingParameterError
func (*ErrorResponse) HTTPStatus ¶
func (error *ErrorResponse) HTTPStatus() int
HTTPStatus returns ErrorResponse.Status
func (*ErrorResponse) Marshal ¶
func (error *ErrorResponse) Marshal() ([]byte, error)
Marshal marshals ErrorResponse
type Request ¶
type Request interface {
Validate(params ...interface{}) error
}
Response represents request. Params are additional parameters required to validate the request.
type SpecialValuesConvertable ¶
type SpecialValuesConvertable interface { FromRequestSpecial(r *http.Request, destination interface{}) error ToValuesSpecial(values url.Values) }
SpecialValuesConvertable allows converting special values (not easily convertable): * from struct to url.Values * from http.Request to struct
type SuccessResponse ¶
type SuccessResponse struct{}
SuccessResponse can be embedded in success responses
func (*SuccessResponse) HTTPStatus ¶
func (r *SuccessResponse) HTTPStatus() int