监控网页实现

This commit is contained in:
Z
2026-04-09 00:14:57 +08:00
parent 6b1c7242c7
commit 1cce5634b1
17 changed files with 1186 additions and 38 deletions

View File

@@ -0,0 +1,38 @@
//go:build windows
package monitor
import (
"os"
"path/filepath"
"golang.org/x/sys/windows"
)
func getDiskSpaceGB() (float64, float64) {
wd, err := os.Getwd()
if err != nil {
return 0, 0
}
vol := filepath.VolumeName(wd)
if vol == "" {
return 0, 0
}
root := vol + `\\`
pathPtr, err := windows.UTF16PtrFromString(root)
if err != nil {
return 0, 0
}
var freeBytesAvailable uint64
var totalBytes uint64
var totalFreeBytes uint64
if err := windows.GetDiskFreeSpaceEx(pathPtr, &freeBytesAvailable, &totalBytes, &totalFreeBytes); err != nil {
return 0, 0
}
const gb = 1024.0 * 1024.0 * 1024.0
return float64(totalBytes) / gb, float64(totalFreeBytes) / gb
}