feat(cluster): 增加删除方法

This commit is contained in:
wangzhengkun
2021-06-04 11:03:16 +08:00
parent 544dea6ea2
commit a44dedd4c4
6 changed files with 74 additions and 8 deletions

View File

@@ -93,9 +93,23 @@ func (h *Handler) ListAll() iris.Handler {
}
}
func (h *Handler) Delete() iris.Handler {
return func(ctx *context.Context) {
name := ctx.Params().GetString("name")
err := h.clusterService.Delete(name)
if err != nil {
ctx.StatusCode(iris.StatusBadRequest)
ctx.Values().Set("message", fmt.Sprintf("delete cluster failed: %s", err.Error()))
return
}
ctx.StatusCode(iris.StatusOK)
}
}
func Install(parent iris.Party) {
handler := NewHandler()
sp := parent.Party("/clusters")
sp.Post("", handler.Create())
sp.Get("", handler.ListAll())
sp.Delete("/{name:string}", handler.Delete())
}