http urls monitor.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package mapstructure
  2. import (
  3. "errors"
  4. "fmt"
  5. "sort"
  6. "strings"
  7. )
  8. // Error implements the error interface and can represents multiple
  9. // errors that occur in the course of a single decode.
  10. type Error struct {
  11. Errors []string
  12. }
  13. func (e *Error) Error() string {
  14. points := make([]string, len(e.Errors))
  15. for i, err := range e.Errors {
  16. points[i] = fmt.Sprintf("* %s", err)
  17. }
  18. sort.Strings(points)
  19. return fmt.Sprintf(
  20. "%d error(s) decoding:\n\n%s",
  21. len(e.Errors), strings.Join(points, "\n"))
  22. }
  23. // WrappedErrors implements the errwrap.Wrapper interface to make this
  24. // return value more useful with the errwrap and go-multierror libraries.
  25. func (e *Error) WrappedErrors() []error {
  26. if e == nil {
  27. return nil
  28. }
  29. result := make([]error, len(e.Errors))
  30. for i, e := range e.Errors {
  31. result[i] = errors.New(e)
  32. }
  33. return result
  34. }
  35. func appendErrors(errors []string, err error) []string {
  36. switch e := err.(type) {
  37. case *Error:
  38. return append(errors, e.Errors...)
  39. default:
  40. return append(errors, e.Error())
  41. }
  42. }