liuxiaolong
2022-06-28 37714b1093c04061e636e5b1d27179652e671c0a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package multierror
 
import (
    "fmt"
    "strings"
)
 
// ErrorFormatFunc is a function callback that is called by Error to
// turn the list of errors into a string.
type ErrorFormatFunc func([]error) string
 
// ListFormatFunc is a basic formatter that outputs the number of errors
// that occurred along with a bullet point list of the errors.
func ListFormatFunc(es []error) string {
    if len(es) == 1 {
        return fmt.Sprintf("1 error occurred:\n\t* %s\n\n", es[0])
    }
 
    points := make([]string, len(es))
    for i, err := range es {
        points[i] = fmt.Sprintf("* %s", err)
    }
 
    return fmt.Sprintf(
        "%d errors occurred:\n\t%s\n\n",
        len(es), strings.Join(points, "\n\t"))
}