1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-24 13:48:56 +08:00

32 lines
517 B
Go
Raw Normal View History

// SPDX-License-Identifier: BSD-3-Clause
2022-10-03 13:55:14 -07:00
package common
2022-10-03 13:55:14 -07:00
import "fmt"
type Warnings struct {
2022-10-03 13:55:14 -07:00
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
}
2021-12-22 23:49:50 +01:00
return nil
}
func (w *Warnings) Error() string {
2022-10-03 13:55:14 -07:00
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))
}