[ci skip] more suggested improvements
This commit is contained in:
@@ -29,12 +29,7 @@ func (h *Handler) VmImport(w http.ResponseWriter, r *http.Request) {
|
||||
reqBody, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
h.Logger.Error("Invalid data received", "length", len(reqBody), "error", err)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"status": "ERROR",
|
||||
"message": fmt.Sprintf("Invalid data received: '%s'", err),
|
||||
})
|
||||
writeJSONError(w, http.StatusInternalServerError, fmt.Sprintf("Invalid data received: '%s'", err))
|
||||
return
|
||||
|
||||
} else {
|
||||
@@ -45,12 +40,7 @@ func (h *Handler) VmImport(w http.ResponseWriter, r *http.Request) {
|
||||
var inData models.ImportReceived
|
||||
if err := json.Unmarshal(reqBody, &inData); err != nil {
|
||||
h.Logger.Error("Unable to decode json request body", "length", len(reqBody), "error", err)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"status": "ERROR",
|
||||
"message": fmt.Sprintf("Unable to decode json request body: '%s'", err),
|
||||
})
|
||||
writeJSONError(w, http.StatusInternalServerError, fmt.Sprintf("Unable to decode json request body: '%s'", err))
|
||||
return
|
||||
} else {
|
||||
//h.Logger.Debug("successfully decoded JSON")
|
||||
@@ -59,12 +49,7 @@ func (h *Handler) VmImport(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if strings.HasPrefix(inData.Name, "vCLS-") {
|
||||
h.Logger.Info("Skipping internal vCLS VM import", "vm_name", inData.Name)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"status": "OK",
|
||||
"message": fmt.Sprintf("Skipped internal VM '%s'", inData.Name),
|
||||
})
|
||||
writeJSONOKMessage(w, fmt.Sprintf("Skipped internal VM '%s'", inData.Name))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -103,10 +88,5 @@ func (h *Handler) VmImport(w http.ResponseWriter, r *http.Request) {
|
||||
h.Logger.Info("not adding vm to inventory table since record alraedy exists", "vm_id", inData.VmId, "datacenter_name", inData.Datacenter)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"status": "OK",
|
||||
"message": fmt.Sprintf("Successfully processed import request for VM '%s'", inData.Name),
|
||||
})
|
||||
writeJSONOKMessage(w, fmt.Sprintf("Successfully processed import request for VM '%s'", inData.Name))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user