41 lines
763 B
Go
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)
|
|
}
|
|
}
|