Files
up_go/api/MountStatus.go
wt 7f0e5b7b10
Build / Build (push) Successful in 10s
up some deprecated fixes
2026-03-19 14:54:33 +07:00

41 lines
763 B
Go

package api
import (
"bufio"
"encoding/json"
"fmt"
"net/http"
"os"
"strings"
)
func MountStatus(w http.ResponseWriter, req *http.Request) {
var MOUNT_POINT = os.Getenv("MOUNT_POINT")
var DEVICE = os.Getenv("DEVICE")
mounted := false
f, err := os.Open("/proc/mounts")
if err == nil {
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, MOUNT_POINT) {
mounted = true
break
}
}
}
response := map[string]interface{}{
"mounted": mounted,
"mount_point": MOUNT_POINT,
"device": DEVICE,
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(response); err != nil {
fmt.Errorf("Encoding error: %v", err)
}
}