-
Notifications
You must be signed in to change notification settings - Fork 5
/
mirror.go
61 lines (50 loc) · 923 Bytes
/
mirror.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package errors
import "errors"
// Unwrap calls the Go builtin errors.UnUnwrap
func Unwrap(err error) error {
return errors.Unwrap(err)
}
// Is calls the Go builtin errors.Is
func Is(err, target error) bool {
return errors.Is(err, target)
}
// As calls the Go builtin errors.As
func As(err error, target interface{}) bool {
return errors.As(err, target)
}
func Join(errs ...error) error {
n := len(errs)
if n == 0 {
return nil
}
e := &joinError{
errs: make([]error, 0, n),
}
for _, err := range errs {
if err == nil {
continue
}
e.errs = append(e.errs, err)
}
n = len(e.errs)
if n == 0 {
return nil
}
return e
}
type joinError struct {
errs []error
}
func (e *joinError) Error() string {
var b []byte
for i, err := range e.errs {
if i > 0 {
b = append(b, '\n')
}
b = append(b, err.Error()...)
}
return string(b)
}
func (e *joinError) Unwrap() []error {
return e.errs
}