2020-06-23 22:11:01 +02:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2020-10-02 03:16:58 +02:00
|
|
|
|
|
|
|
"github.com/gabek/owncast/models"
|
2020-06-23 22:11:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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()})
|
|
|
|
}
|
2020-10-02 03:16:58 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|