refactor: switch router to gin

This commit is contained in:
Nicolas Meienberger
2025-08-10 13:07:05 +02:00
parent e601d91955
commit 2c38a551cc
15 changed files with 277 additions and 131 deletions

View File

@@ -1,27 +1,30 @@
package driver
import (
"encoding/json"
"ironmount/internal/constants"
"ironmount/internal/db"
"net/http"
"os"
"path/filepath"
"github.com/rs/zerolog/hlog"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
func Remove(w http.ResponseWriter, r *http.Request) {
func Remove(c *gin.Context) {
var req RemoveRequest
_ = json.NewDecoder(r.Body).Decode(&req)
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 {
hlog.FromRequest(r).Error().Err(err).Msg("Error retrieving volume")
_ = json.NewEncoder(w).Encode(map[string]string{
"Err": err.Error(),
})
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
}
@@ -31,5 +34,7 @@ func Remove(w http.ResponseWriter, r *http.Request) {
log.Info().Str("path", volPathLocal).Msg("Removing volume directory")
os.RemoveAll(volPathLocal)
_ = json.NewEncoder(w).Encode(map[string]string{"Err": ""})
c.JSON(http.StatusOK, gin.H{
"Err": "",
})
}