Documentation ¶
Index ¶
Constants ¶
View Source
const ( SUCCESS = 0 FAILURE = 1 ERROR = 2 )
Variables ¶
View Source
var ( // When set to true, Failure() and Error() will write to log. // This is enabled by default. Log = true // HTTP codes send when appropriate function is used. // All status OK by default. SuccessHttpCode = http.StatusOK FailureHttpCode = http.StatusOK ErrorHttpCode = http.StatusOK )
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, code int, msg string, data interface{}) error
Sends an error response with given code, message and data to the client. The first argument must be the ResponseWriter.
Types ¶
type Resp ¶
type Resp struct { Type int `json:"type"` Code int `json:"code"` Msg string `json:"msg"` Data interface{} `json:"data"` // contains filtered or unexported fields }
Response of type "success", "failure" or "error" with error code, a short message and additional data. The data will be marshalled to JSON and must have decorators for all fields which are supposed to be send to the client. The type can be used to differentiate between different kind of outcomes:
success = everything went fine, the operation was successful failure = the operation failed due to wrong input or usage error = a technical error occured
Click to show internal directories.
Click to hide internal directories.