Files
baseapi/utils/errlist/errlist.go
2019-07-22 13:33:49 +08:00

38 lines
628 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package errlist
import (
"fmt"
"strings"
)
type ErrList struct {
errList []error
}
func New() *ErrList {
return &ErrList{}
}
func (l *ErrList) AddErr(err error) *ErrList {
if err != nil {
l.errList = append(l.errList, err)
}
return l
}
func (l *ErrList) GetErrListAsOne() (err error) {
errLen := len(l.errList)
if errLen > 0 {
if errLen == 1 {
err = l.errList[0]
} else {
errStrList := make([]string, errLen)
for k, v := range l.errList {
errStrList[k] = v.Error()
}
err = fmt.Errorf("总共%d个错误详情如下\n%s", errLen, strings.Join(errStrList, ",\n"))
}
}
return err
}