github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/sysinfo/disk/disk.go (about) 1 package disk 2 3 import ( 4 "runtime" 5 6 "github.com/shirou/gopsutil/disk" 7 ) 8 9 // Useage Total总量,Idle空闲,Used使用率,Collercter总量,使用量 10 type Useage struct { 11 Total uint64 `json:"total"` 12 Idle uint64 `json:"idle"` 13 UsedPercent float64 `json:"percent"` 14 } 15 16 // GetInfo 获取磁盘使用信息 17 func GetInfo() (useage Useage) { 18 dir := "/" 19 if runtime.GOOS == "windows" { 20 dir = "c:" 21 } 22 sm, _ := disk.Usage(dir) 23 24 useage.Total = sm.Total 25 useage.Idle = sm.Total - sm.Used 26 useage.UsedPercent = sm.UsedPercent 27 return 28 }