godash/src/system/disk.go
2023-06-14 21:53:27 +02:00

33 lines
655 B
Go

package system
import (
"math"
"strconv"
"github.com/dariubs/percent"
"github.com/shirou/gopsutil/v3/disk"
)
func staticDisk() Disk {
var result = Disk{}
d, err := disk.Usage("/")
if err != nil {
return result
}
p, err := disk.Partitions(false)
if err != nil {
return result
}
result.Total = readableSize(d.Total)
result.Partitions = strconv.Itoa(len(p)) + " partitions"
return result
}
func (c *Config) liveDisk() {
d, err := disk.Usage("/")
if err != nil {
return
}
c.System.Live.Disk.Value = readableSize(d.Used)
c.System.Live.Disk.Percentage = math.RoundToEven(percent.PercentOfFloat(float64(d.Used), float64(d.Total)))
}