mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: basic volume plugin commands
This commit is contained in:
50
main.go
50
main.go
@@ -1,20 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ironmount/internal/driver"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "Hello, World!")
|
||||
const volumeRoot = "/tmp/ironmount"
|
||||
|
||||
type Volume struct {
|
||||
Name string
|
||||
Path string
|
||||
}
|
||||
|
||||
var volumes = map[string]Volume{}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", handler)
|
||||
|
||||
fmt.Println("Server is running on http://localhost:8080")
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
if err != nil {
|
||||
fmt.Println("Error starting server:", err)
|
||||
if err := os.MkdirAll("/run/docker/plugins", 0755); err != nil {
|
||||
log.Fatalf("Failed to create plugin directory: %v", err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(volumeRoot, 0755); err != nil {
|
||||
log.Fatalf("Failed to create volume root: %v", err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll("/run/docker/plugins", 0755); err != nil {
|
||||
log.Fatalf("Failed to create plugin directory: %v", err)
|
||||
}
|
||||
|
||||
socketPath := "/run/docker/plugins/ironmount.sock"
|
||||
if err := os.RemoveAll(socketPath); err != nil {
|
||||
log.Fatalf("Failed to remove existing socket: %v", err)
|
||||
}
|
||||
|
||||
http.HandleFunc("/Plugin.Activate", driver.Activate)
|
||||
http.HandleFunc("/VolumeDriver.Create", driver.Create)
|
||||
http.HandleFunc("/VolumeDriver.Remove", driver.Remove)
|
||||
http.HandleFunc("/VolumeDriver.Mount", driver.Mount)
|
||||
http.HandleFunc("/VolumeDriver.Unmount", driver.Unmount)
|
||||
http.HandleFunc("/VolumeDriver.Path", driver.Path)
|
||||
|
||||
listener, err := net.Listen("unix", socketPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to listen on socket: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("Irounmount plugin started, listening on %s", socketPath)
|
||||
log.Fatal(http.Serve(listener, nil))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user