mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-02 22:17:08 +08:00

Remains backward compatible. When encountering non-fatal errors SensorsTemperatures() returns the temperatures for all the sensor we could read successfully. In that case the custom error contains a list of all the non-fatal errors encountered. Example usage: _, err := SensorsTemperatures() if err != nil { warns, ok := err.(*Warnings) if ok { fmt.Printf("%v\n", err) for i, w := range warns.List { fmt.Printf("Warning %v: %v\n", i+1, w) } } else { t.Errorf("%v", err) } }
26 lines
346 B
Go
26 lines
346 B
Go
package host
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type Warnings struct {
|
|
List []error
|
|
}
|
|
|
|
func (w *Warnings) Add(err error) {
|
|
w.List = append(w.List, err)
|
|
}
|
|
|
|
func (w *Warnings) Reference() error {
|
|
if len(w.List) > 0 {
|
|
return w
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (w *Warnings) Error() string {
|
|
return fmt.Sprintf("Number of warnings: %v", len(w.List))
|
|
}
|