package cli import ( "encoding/json" "net/http" "sort" ) func (h *abraHandler) handleGetAppServices(w http.ResponseWriter, r *http.Request, appName string) { var tmpMsg map[string]map[string]string output, err := h.cmd.Run("abra", "app", "ps", appName, "-m") if err != nil { InternalServerError(w, err) return } if err = json.Unmarshal(output, &tmpMsg); err != nil { InternalServerError(w, err) return } var services []AbraAppService for _, v := range tmpMsg { services = append(services, AbraAppService{ Service: v["service"], Chaos: v["chaos"] == "true", Created: v["created"], Image: v["image"], Ports: v["ports"], State: v["state"], Status: v["status"], Version: v["version"], }) } sort.Slice(services, func(i, j int) bool { return services[i].Service < services[j].Service }) jsonBytes, err := json.Marshal(services) if err != nil { InternalServerError(w, err) return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write(jsonBytes) }