mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: missing endpoints
This commit is contained in:
@@ -14,6 +14,7 @@ func Create(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req struct {
|
||||
Name string
|
||||
Opts map[string]string `json:"Opts,omitempty"`
|
||||
}
|
||||
_ = json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
@@ -23,6 +24,12 @@ func Create(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
volumes[req.Name] = Volume{Name: req.Name, Path: volPath}
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"Err": ""})
|
||||
response := map[string]string{
|
||||
"Name": req.Name,
|
||||
"Mountpoint": volPath,
|
||||
"Err": "",
|
||||
}
|
||||
|
||||
volumes[req.Name] = Volume{Name: req.Name, Path: volPath}
|
||||
_ = json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
|
||||
29
internal/driver/get.go
Normal file
29
internal/driver/get.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package driver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Get(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received get request: %s", r.URL.Path)
|
||||
|
||||
var req struct {
|
||||
Name string
|
||||
}
|
||||
_ = json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
vol := volumes[req.Name]
|
||||
|
||||
response := map[string]any{
|
||||
"Volume": map[string]any{
|
||||
"Name": vol.Name,
|
||||
"Mountpoint": vol.Path,
|
||||
"Status": map[string]string{},
|
||||
},
|
||||
"Err": "",
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
22
internal/driver/list.go
Normal file
22
internal/driver/list.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package driver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"Volumes": vols,
|
||||
"Err": "",
|
||||
})
|
||||
}
|
||||
8
main.go
8
main.go
@@ -41,6 +41,14 @@ func main() {
|
||||
http.HandleFunc("/VolumeDriver.Mount", driver.Mount)
|
||||
http.HandleFunc("/VolumeDriver.Unmount", driver.Unmount)
|
||||
http.HandleFunc("/VolumeDriver.Path", driver.Path)
|
||||
http.HandleFunc("/VolumeDriver.Get", driver.Get)
|
||||
http.HandleFunc("/VolumeDriver.List", driver.List)
|
||||
|
||||
// Catch all other paths to return an error
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received unknown request: %s", r.URL.Path)
|
||||
http.Error(w, "Not Found", http.StatusNotFound)
|
||||
})
|
||||
|
||||
listener, err := net.Listen("unix", socketPath)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user