Files
ironmount/internal/driver/remove.go
2025-08-10 13:07:05 +02:00

41 lines
877 B
Go

package driver
import (
"ironmount/internal/constants"
"ironmount/internal/db"
"net/http"
"os"
"path/filepath"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
func Remove(c *gin.Context) {
var req RemoveRequest
if err := c.BindJSON(&req); err != nil {
log.Error().Err(err).Msg("Invalid request body for Remove")
c.JSON(http.StatusBadRequest, gin.H{"Err": "Invalid request body"})
return
}
vol, err := db.GetVolumeByName(req.Name)
if err != nil {
log.Error().Err(err).Str("volume", req.Name).Msg("Failed to get volume by name")
c.JSON(http.StatusNotFound, gin.H{"Err": err.Error()})
return
}
db.RemoveVolume(vol.Name)
volPathLocal := filepath.Join(constants.VolumeRootLocal, req.Name)
log.Info().Str("path", volPathLocal).Msg("Removing volume directory")
os.RemoveAll(volPathLocal)
c.JSON(http.StatusOK, gin.H{
"Err": "",
})
}