diff --git a/disk/disk_windows.go b/disk/disk_windows.go index b7f0c51..3e3d991 100644 --- a/disk/disk_windows.go +++ b/disk/disk_windows.go @@ -80,7 +80,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { } func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { - warnings := common.Warnings{ + warnings := Warnings{ Verbose: true, } var ret []PartitionStat diff --git a/internal/common/warnings.go b/disk/warnings.go similarity index 96% rename from internal/common/warnings.go rename to disk/warnings.go index a4aaada..ce13aa9 100644 --- a/internal/common/warnings.go +++ b/disk/warnings.go @@ -1,4 +1,4 @@ -package common +package disk import "fmt" diff --git a/host/host_linux.go b/host/host_linux.go index a6bb3fc..940415c 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -395,7 +395,7 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err } } - var warns common.Warnings + var warns Warnings if len(files) == 0 { // handle distributions without hwmon, like raspbian #391, parse legacy thermal_zone files files, err = filepath.Glob(common.HostSys("/class/thermal/thermal_zone*/")) diff --git a/host/warnings.go b/host/warnings.go new file mode 100644 index 0000000..182a293 --- /dev/null +++ b/host/warnings.go @@ -0,0 +1,30 @@ +package host + +import "fmt" + +type Warnings struct { + List []error + Verbose bool +} + +func (w *Warnings) Add(err error) { + w.List = append(w.List, err) +} + +func (w *Warnings) Reference() error { + if len(w.List) > 0 { + return w + } + return nil +} + +func (w *Warnings) Error() string { + if w.Verbose { + str := "" + for i, e := range w.List { + str += fmt.Sprintf("\tError %d: %s\n", i, e.Error()) + } + return str + } + return fmt.Sprintf("Number of warnings: %v", len(w.List)) +}