Documentation ¶
Overview ¶
Package responses contains handlers for HTTP response.
Index ¶
- func BuildOkResponse() map[string]interface{}
- func BuildOkResponseWithData(dataName string, data interface{}) map[string]interface{}
- func BuildResponse(status string) map[string]interface{}
- func Send(statusCode int, w http.ResponseWriter, data interface{}) error
- func SendAccepted(w http.ResponseWriter, data map[string]interface{}) error
- func SendBadRequest(w http.ResponseWriter, errorMessage string) error
- func SendCreated(w http.ResponseWriter, data map[string]interface{}) error
- func SendForbidden(w http.ResponseWriter, errorMessage string) error
- func SendInternalServerError(w http.ResponseWriter, errorMessage string) error
- func SendNoContent(w http.ResponseWriter) error
- func SendNotFound(w http.ResponseWriter, errorMessage string) error
- func SendOK(w http.ResponseWriter, data map[string]interface{}) error
- func SendServiceUnavailable(w http.ResponseWriter, errorMessage string) error
- func SendUnauthorized(w http.ResponseWriter, errorMessage string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildOkResponse ¶
func BuildOkResponse() map[string]interface{}
BuildOkResponse builds simple "ok" response
func BuildOkResponseWithData ¶
BuildOkResponseWithData builds response with status "ok" and data
func BuildResponse ¶
BuildResponse builds response for RestAPI request
func Send ¶
func Send(statusCode int, w http.ResponseWriter, data interface{}) error
Send sends HTTP response with a provided statusCode data can be either string or map[string]interface{} if data is string it will send response like this: {"status": data} which is helpful for explaining error to the client
Returned error value is based on error returned from json.Encoder
func SendAccepted ¶
func SendAccepted(w http.ResponseWriter, data map[string]interface{}) error
SendAccepted returns response with status Accepted 202
func SendBadRequest ¶ added in v1.0.0
func SendBadRequest(w http.ResponseWriter, errorMessage string) error
SendBadRequest returns error response with status Bad Request 400
func SendCreated ¶
func SendCreated(w http.ResponseWriter, data map[string]interface{}) error
SendCreated returns response with status Created 201
func SendForbidden ¶
func SendForbidden(w http.ResponseWriter, errorMessage string) error
SendForbidden returns response with status Forbidden 403
func SendInternalServerError ¶
func SendInternalServerError(w http.ResponseWriter, errorMessage string) error
SendInternalServerError returns response with status Internal Server Error 500
func SendNoContent ¶ added in v1.24.6
func SendNoContent(w http.ResponseWriter) error
SendNoContent returns error response with status SendNoContent 204
func SendNotFound ¶
func SendNotFound(w http.ResponseWriter, errorMessage string) error
SendNotFound returns response with status Not Found 404
func SendOK ¶ added in v1.0.0
func SendOK(w http.ResponseWriter, data map[string]interface{}) error
SendOK returns JSON response with status OK 200
func SendServiceUnavailable ¶ added in v1.0.1
func SendServiceUnavailable(w http.ResponseWriter, errorMessage string) error
SendServiceUnavailable returns response with status Service Unavailable 503
func SendUnauthorized ¶
func SendUnauthorized(w http.ResponseWriter, errorMessage string) error
SendUnauthorized returns error response for unauthorized access with status Unauthorized 401
Types ¶
This section is empty.