sk-matrix-project/app/wails/pkg/system/disk.go

55 lines
1.1 KiB
Go
Raw Normal View History

2023-07-09 23:04:17 +08:00
package system
import (
"github.com/shirou/gopsutil/disk"
"os"
"path/filepath"
"time"
)
2023-07-15 23:29:03 +08:00
func (i *InfoUtils) GetDiskPartitions() []disk.PartitionStat {
2023-07-09 23:04:17 +08:00
partitions, _ := disk.Partitions(true)
return partitions
}
2023-07-15 23:29:03 +08:00
func (i *InfoUtils) GetDiskUsage(diskPath string) *disk.UsageStat {
2023-07-09 23:04:17 +08:00
usageStat, _ := disk.Usage(diskPath)
return usageStat
}
2023-07-15 23:29:03 +08:00
func (i *InfoUtils) GetIOCounters() map[string]disk.IOCountersStat {
2023-07-09 23:04:17 +08:00
info, _ := disk.IOCounters()
return info
}
type FileEntry struct {
Path string
Name string
IsDir bool
IsSymlink bool
ModTime time.Time
Size int64
}
2023-07-15 23:29:03 +08:00
func (i *InfoUtils) ScanDir(path string) ([]*FileEntry, error) {
2023-07-09 23:04:17 +08:00
entries, err := os.ReadDir(path)
data := make([]*FileEntry, 0, len(entries))
for _, entry := range entries {
info, _ := entry.Info()
_path := filepath.Join(path, entry.Name())
info.Size()
info.ModTime()
data = append(data, &FileEntry{
Path: _path,
Name: entry.Name(),
IsDir: entry.IsDir(),
IsSymlink: entry.Type() == os.ModeSymlink,
Size: info.Size(),
ModTime: info.ModTime(),
})
}
return data, err
}