add error detect

This commit is contained in:
Jason
2019-08-16 16:54:27 +08:00
parent a4216559c5
commit 494551190e

View File

@@ -16,12 +16,18 @@ func init() {
}
func cpu() string {
c, _ := C.Percent(0, false)
c, err := C.Percent(0, false)
if err != nil || len(c) != 1 {
return "N/A"
}
return fmt.Sprintf("%.1f%%", c[0])
}
func mem() string {
m, _ := M.VirtualMemory()
m, err := M.VirtualMemory()
if err != nil {
return "N/A"
}
return fmt.Sprintf("%.1f%%", m.UsedPercent)
}