//HandleSuccess returns message as successful json response. func HandleSuccess(responseWriter http.ResponseWriter, message string) { jsonResponse := models.ResponseMessage{} jsonResponse.Success = true jsonResponse.Response = message jsonResponseString, _ := json.Marshal(jsonResponse) http.Error(responseWriter, string(jsonResponseString), http.StatusOK) }
//HandleError checks if passed in error is not null, logs it, and sets response status code and message as json. func HandleError(responseWriter http.ResponseWriter, err error, message string, statusCode int) bool { if err != nil { WriteLog(err.Error()) jsonResponse := models.ResponseMessage{} jsonResponse.Success = false jsonResponse.Response = message jsonResponseString, _ := json.Marshal(jsonResponse) http.Error(responseWriter, string(jsonResponseString), statusCode) return true } return false }