签入脚本

This commit is contained in:
小蚂蚁云
2026-10-20 11:37:25 +08:00
commit 7f5e8470af
909 changed files with 4045080 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
//go:build windows
package logic
import (
"math"
"os"
"golang.org/x/sys/windows"
"easygoadmin/api/v1"
)
// diskUsage 读取工作目录所在磁盘分区容量(Windows)
func diskUsage() []v1.ServerDiskInfo {
wd, err := os.Getwd()
if err != nil || len(wd) < 3 {
return nil
}
root := wd[:3] // 形如 "E:\"
handle, err := windows.UTF16PtrFromString(root)
if err != nil {
return nil
}
var freeBytes, totalBytes, totalFreeBytes uint64
if err = windows.GetDiskFreeSpaceEx(handle, &freeBytes, &totalBytes, &totalFreeBytes); err != nil {
return nil
}
total := float64(totalBytes) / 1073741824
free := float64(freeBytes) / 1073741824
usedPercent := 0.0
if total > 0 {
usedPercent = math.Round((total-free)/total*10000) / 100
}
return []v1.ServerDiskInfo{{
Path: root,
TotalGB: math.Round(total*100) / 100,
FreeGB: math.Round(free*100) / 100,
UsedPercent: usedPercent,
}}
}