feat: sqlite storage

This commit is contained in:
Nicolas Meienberger
2025-08-09 19:54:29 +02:00
parent 388114d536
commit d0bf890386
14 changed files with 189 additions and 26 deletions

View File

@@ -3,6 +3,7 @@ package driver
import (
"encoding/json"
"ironmount/internal/constants"
"ironmount/internal/db"
"log"
"net/http"
"os"
@@ -24,12 +25,13 @@ func Create(w http.ResponseWriter, r *http.Request) {
return
}
db.CreateVolume(req.Name, volPath)
response := map[string]string{
"Name": req.Name,
"Mountpoint": volPath,
"Err": "",
}
volumes[req.Name] = Volume{Name: req.Name, Path: volPath}
_ = json.NewEncoder(w).Encode(response)
}

View File

@@ -2,6 +2,7 @@ package driver
import (
"encoding/json"
"ironmount/internal/db"
"log"
"net/http"
)
@@ -14,7 +15,18 @@ func Get(w http.ResponseWriter, r *http.Request) {
}
_ = json.NewDecoder(r.Body).Decode(&req)
vol := volumes[req.Name]
vol, err := db.GetVolumeByName(req.Name)
if err != nil {
log.Printf("Error retrieving volume: %s", err.Error())
response := map[string]string{
"Err": err.Error(),
}
_ = json.NewEncoder(w).Encode(response)
return
}
response := map[string]any{
"Volume": map[string]any{

View File

@@ -2,6 +2,7 @@ package driver
import (
"encoding/json"
"ironmount/internal/db"
"log"
"net/http"
)
@@ -9,14 +10,18 @@ import (
func List(w http.ResponseWriter, r *http.Request) {
log.Printf("Received list request: %s", r.URL.Path)
var vols []map[string]string
for _, v := range volumes {
vols = append(vols, map[string]string{
"Name": v.Name,
volumes, err := db.ListVolumes()
if err != nil {
log.Printf("Error listing volumes: %s", err.Error())
json.NewEncoder(w).Encode(map[string]any{
"Volumes": nil,
"Err": err.Error(),
})
return
}
json.NewEncoder(w).Encode(map[string]interface{}{
"Volumes": vols,
json.NewEncoder(w).Encode(map[string]any{
"Volumes": volumes,
"Err": "",
})
}

View File

@@ -2,6 +2,7 @@ package driver
import (
"encoding/json"
"ironmount/internal/db"
"log"
"net/http"
)
@@ -17,9 +18,12 @@ func Mount(w http.ResponseWriter, r *http.Request) {
return
}
vol, ok := volumes[req.Name]
if !ok {
_ = json.NewEncoder(w).Encode(map[string]string{"Err": "volume not found"})
vol, err := db.GetVolumeByName(req.Name)
if err != nil {
log.Printf("Error retrieving volume: %s", err.Error())
_ = json.NewEncoder(w).Encode(map[string]string{
"Err": err.Error(),
})
return
}

View File

@@ -2,6 +2,7 @@ package driver
import (
"encoding/json"
"ironmount/internal/db"
"log"
"net/http"
)
@@ -12,9 +13,11 @@ func Path(w http.ResponseWriter, r *http.Request) {
var req PathRequest
_ = json.NewDecoder(r.Body).Decode(&req)
vol, ok := volumes[req.Name]
if !ok {
_ = json.NewEncoder(w).Encode(map[string]string{"Err": "volume not found"})
vol, err := db.GetVolumeByName(req.Name)
if err != nil {
_ = json.NewEncoder(w).Encode(map[string]string{
"Err": err.Error(),
})
return
}

View File

@@ -2,8 +2,10 @@ package driver
import (
"encoding/json"
"ironmount/internal/db"
"log"
"net/http"
"os"
)
func Remove(w http.ResponseWriter, r *http.Request) {
@@ -12,6 +14,17 @@ func Remove(w http.ResponseWriter, r *http.Request) {
var req RemoveRequest
_ = json.NewDecoder(r.Body).Decode(&req)
delete(volumes, req.Name)
vol, err := db.GetVolumeByName(req.Name)
if err != nil {
log.Printf("Error retrieving volume: %s", err.Error())
_ = json.NewEncoder(w).Encode(map[string]string{
"Err": err.Error(),
})
return
}
db.RemoveVolume(vol.Name)
os.RemoveAll(vol.Path)
_ = json.NewEncoder(w).Encode(map[string]string{"Err": ""})
}

View File

@@ -1,8 +0,0 @@
package driver
type Volume struct {
Name string
Path string
}
var volumes = map[string]Volume{}