mirror of
https://github.com/owncast/owncast.git
synced 2024-11-24 21:59:43 +03:00
769fc3a561
Co-authored-by: Michael Leow <mleow@moneylion.com>
37 lines
736 B
Go
37 lines
736 B
Go
package controllers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/owncast/owncast/models"
|
|
)
|
|
|
|
type j map[string]interface{}
|
|
|
|
func internalErrorHandler(w http.ResponseWriter, err error) {
|
|
if err == nil {
|
|
return
|
|
}
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
json.NewEncoder(w).Encode(j{"error": err.Error()})
|
|
}
|
|
|
|
func badRequestHandler(w http.ResponseWriter, err error) {
|
|
if err == nil {
|
|
return
|
|
}
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
json.NewEncoder(w).Encode(j{"error": err.Error()})
|
|
}
|
|
|
|
func WriteSimpleResponse(w http.ResponseWriter, success bool, message string) {
|
|
response := models.BaseAPIResponse{
|
|
Success: success,
|
|
Message: message,
|
|
}
|
|
w.WriteHeader(http.StatusOK)
|
|
json.NewEncoder(w).Encode(response)
|
|
}
|