Skip to content

Commit

Permalink
Merge pull request opskumu#46 from joylili/master
Browse files Browse the repository at this point in the history
增加chart删除方法
  • Loading branch information
opskumu authored Dec 30, 2021
2 parents b909435 + 55d134c commit 1a8535e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions upload.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -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)
}

0 comments on commit 1a8535e

Please sign in to comment.