Rainbond/api/controller/enterprise.go
Quyc dac119b5ee
feat: personal space page (#1391)
Co-authored-by: 曲源成 <quyc@goodrain.com>
2022-10-26 12:09:35 +08:00

47 lines
1.4 KiB
Go

package controller
import (
typesv1 "github.com/goodrain/rainbond/worker/appm/types/v1"
"net/http"
"github.com/go-chi/chi"
"github.com/goodrain/rainbond/api/handler"
httputil "github.com/goodrain/rainbond/util/http"
)
//GetRunningServices list all running service ids
func GetRunningServices(w http.ResponseWriter, r *http.Request) {
enterpriseID := chi.URLParam(r, "enterprise_id")
serviceStatusList, err := handler.GetServiceManager().GetEnterpriseServicesStatus(enterpriseID)
if err != nil {
err.Handle(r, w)
return
}
retServices := make([]string, 0, 10)
for service, status := range serviceStatusList {
if status == typesv1.RUNNING {
retServices = append(retServices, service)
}
}
httputil.ReturnNoFomart(r, w, 200, map[string]interface{}{"service_ids": retServices})
}
//GetAbnormalStatus -
func GetAbnormalStatus(w http.ResponseWriter, r *http.Request) {
enterpriseID := chi.URLParam(r, "enterprise_id")
serviceStatusList, err := handler.GetServiceManager().GetEnterpriseServicesStatus(enterpriseID)
if err != nil {
err.Handle(r, w)
return
}
retServices := make([]string, 0, 10)
for service, status := range serviceStatusList {
if status == typesv1.ABNORMAL || status == typesv1.SOMEABNORMAL {
retServices = append(retServices, service)
}
}
httputil.ReturnNoFomart(r, w, 200, map[string]interface{}{"service_ids": retServices})
}