responses

package
v1.24.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2022 License: Apache-2.0 Imports: 2 Imported by: 7

Documentation

Index

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

func BuildOkResponseWithData(dataName string, data interface{}) map[string]interface{}

BuildOkResponseWithData builds response with status "ok" and data

func BuildResponse

func BuildResponse(status string) map[string]interface{}

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 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL