mirror of https://github.com/shirou/gopsutil
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
476 B
Go
31 lines
476 B
Go
2 years ago
|
package common
|
||
6 years ago
|
|
||
2 years ago
|
import "fmt"
|
||
6 years ago
|
|
||
|
type Warnings struct {
|
||
2 years ago
|
List []error
|
||
|
Verbose bool
|
||
6 years ago
|
}
|
||
|
|
||
|
func (w *Warnings) Add(err error) {
|
||
|
w.List = append(w.List, err)
|
||
|
}
|
||
|
|
||
|
func (w *Warnings) Reference() error {
|
||
|
if len(w.List) > 0 {
|
||
|
return w
|
||
|
}
|
||
3 years ago
|
return nil
|
||
6 years ago
|
}
|
||
|
|
||
|
func (w *Warnings) Error() string {
|
||
2 years ago
|
if w.Verbose {
|
||
|
str := ""
|
||
|
for i, e := range w.List {
|
||
|
str += fmt.Sprintf("\tError %d: %s\n", i, e.Error())
|
||
|
}
|
||
|
return str
|
||
|
}
|
||
6 years ago
|
return fmt.Sprintf("Number of warnings: %v", len(w.List))
|
||
6 years ago
|
}
|