mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: improved logging with zerolog
This commit is contained in:
@@ -3,30 +3,34 @@ package driver
|
||||
import (
|
||||
"encoding/json"
|
||||
"ironmount/internal/db"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func Mount(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received mount request: %s", r.URL.Path)
|
||||
|
||||
var req MountRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
if err != nil {
|
||||
hlog.FromRequest(r).Error().Err(err).Msg("Invalid request body")
|
||||
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
vol, err := db.GetVolumeByName(req.Name)
|
||||
if err != nil {
|
||||
log.Printf("Error retrieving volume: %s", err.Error())
|
||||
log.Error().Err(err).Str("volume", req.Name).Msg("Failed to get volume")
|
||||
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
||||
"Err": err.Error(),
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().Str("volume", vol.Name).Str("path", vol.Path).Msg("Mounting volume")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
||||
"Mountpoint": vol.Path,
|
||||
"Err": "",
|
||||
|
||||
Reference in New Issue
Block a user