diff --git a/router.go b/router.go index e1d91da..5bd7eaa 100644 --- a/router.go +++ b/router.go @@ -56,6 +56,8 @@ func RegisterRouter(router *gin.Engine) { charts.POST("/upload", uploadChart) // list uploaded charts charts.GET("/upload", listUploadedCharts) + // delete chart + charts.DELETE("/upload/:chart", deleteChart) } // helm release diff --git a/upload.go b/upload.go index 4f57cbd..d54304e 100644 --- a/upload.go +++ b/upload.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "io/ioutil" @@ -56,3 +57,29 @@ func listUploadedCharts(c *gin.Context) { respOK(c, charts) } + +func deleteChart(c *gin.Context) { + chart := c.Param("chart") + if chart == "" { + err := errors.New("chart must be not empty") + respErr(c, err) + return + } + + filePath := helmConfig.UploadPath + "/" + chart + // not exist,ok + _, err := os.Stat(filePath) + if err != nil || os.IsNotExist(err) { + respOK(c, nil) + return + } + + //delete chart from disk + err = os.Remove(filePath) + if err != nil { + respErr(c, err) + return + } + + respOK(c, nil) +}