mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 19:57:42 +08:00
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi"
|
|
"github.com/goodrain/rainbond/api/handler"
|
|
"github.com/goodrain/rainbond/api/middleware"
|
|
api_model "github.com/goodrain/rainbond/api/model"
|
|
httputil "github.com/goodrain/rainbond/util/http"
|
|
)
|
|
|
|
//AddServiceMonitors add service monitor
|
|
func (t *TenantStruct) AddServiceMonitors(w http.ResponseWriter, r *http.Request) {
|
|
var add api_model.AddServiceMonitorRequestStruct
|
|
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &add, nil)
|
|
if !ok {
|
|
return
|
|
}
|
|
serviceID := r.Context().Value(middleware.ContextKey("service_id")).(string)
|
|
tenantID := r.Context().Value(middleware.ContextKey("tenant_id")).(string)
|
|
tsm, err := handler.GetServiceManager().AddServiceMonitor(tenantID, serviceID, add)
|
|
if err != nil {
|
|
httputil.ReturnBcodeError(r, w, err)
|
|
return
|
|
}
|
|
httputil.ReturnSuccess(r, w, tsm)
|
|
}
|
|
|
|
//DeleteServiceMonitors delete service monitor
|
|
func (t *TenantStruct) DeleteServiceMonitors(w http.ResponseWriter, r *http.Request) {
|
|
serviceID := r.Context().Value(middleware.ContextKey("service_id")).(string)
|
|
tenantID := r.Context().Value(middleware.ContextKey("tenant_id")).(string)
|
|
name := chi.URLParam(r, "name")
|
|
tsm, err := handler.GetServiceManager().DeleteServiceMonitor(tenantID, serviceID, name)
|
|
if err != nil {
|
|
httputil.ReturnBcodeError(r, w, err)
|
|
return
|
|
}
|
|
httputil.ReturnSuccess(r, w, tsm)
|
|
}
|
|
|
|
//UpdateServiceMonitors update service monitor
|
|
func (t *TenantStruct) UpdateServiceMonitors(w http.ResponseWriter, r *http.Request) {
|
|
var update api_model.UpdateServiceMonitorRequestStruct
|
|
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &update, nil)
|
|
if !ok {
|
|
return
|
|
}
|
|
name := chi.URLParam(r, "name")
|
|
serviceID := r.Context().Value(middleware.ContextKey("service_id")).(string)
|
|
tenantID := r.Context().Value(middleware.ContextKey("tenant_id")).(string)
|
|
tsm, err := handler.GetServiceManager().UpdateServiceMonitor(tenantID, serviceID, name, update)
|
|
if err != nil {
|
|
httputil.ReturnBcodeError(r, w, err)
|
|
return
|
|
}
|
|
httputil.ReturnSuccess(r, w, tsm)
|
|
}
|