Documentation ¶
Overview ¶
Package response implements helpers for JSON responses.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataResponse ¶
type DataResponse struct { Code int `json:"-"` Data interface{} `json:"data"` }
DataResponse describes a JSON response containing resource data:
{ data: {...} }
If resource data is an array of objects, the data key will be an array:
{ data: [...] }
func NewDataResponse ¶
func NewDataResponse(resources interface{}) DataResponse
NewDataResponse returns a new DataResponse
func (DataResponse) WithCode ¶
func (r DataResponse) WithCode(code int) DataResponse
WithCode sets the code for the response and returns the DataResponse
func (DataResponse) Write ¶
func (r DataResponse) Write(w http.ResponseWriter)
type ErrorResponse ¶
ErrorResponse describes a JSON error response with the following body:
{ "code": 404, "message": "not found" }
func NewErrorResponse ¶
func NewErrorResponse(code int, message string) ErrorResponse
NewErrorResponse returns a new ErrorResponse
func (ErrorResponse) Write ¶
func (e ErrorResponse) Write(w http.ResponseWriter)
Click to show internal directories.
Click to hide internal directories.