You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

28 lines
668 B

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