cleanups and code fixes incl templ
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@@ -26,6 +25,11 @@ import (
|
||||
// @Failure 500 {object} models.ErrorResponse "Server error"
|
||||
// @Router /api/event/vm/create [post]
|
||||
func (h *Handler) VmCreateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
writeJSONError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||
return
|
||||
}
|
||||
|
||||
if h.denyLegacyAPI(w, "/api/event/vm/create") {
|
||||
return
|
||||
}
|
||||
@@ -39,18 +43,8 @@ func (h *Handler) VmCreateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
//datacenter string
|
||||
)
|
||||
|
||||
reqBody, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
h.Logger.Error("Invalid data received", "error", err)
|
||||
writeJSONError(w, http.StatusInternalServerError, "Invalid data received")
|
||||
return
|
||||
} else {
|
||||
h.Logger.Debug("received input data", "length", len(reqBody))
|
||||
}
|
||||
|
||||
// Decode the JSON body into CloudEventReceived struct
|
||||
var event models.CloudEventReceived
|
||||
if err := json.Unmarshal(reqBody, &event); err != nil {
|
||||
if err := decodeJSONBody(w, r, &event); err != nil {
|
||||
h.Logger.Error("unable to decode json", "error", err)
|
||||
writeJSONError(w, http.StatusBadRequest, "Invalid JSON body")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user