-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
helper.go
45 lines (37 loc) · 659 Bytes
/
helper.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
package dbresolver
import (
"net"
"sync"
"go.uber.org/multierr"
)
func doParallely(n int, fn func(i int) error) error {
errors := make(chan error, n)
wg := &sync.WaitGroup{}
wg.Add(n)
for i := 0; i < n; i++ {
go func(i int) {
errors <- fn(i)
wg.Done()
}(i)
}
go func(wg *sync.WaitGroup) {
wg.Wait()
close(errors)
}(wg)
var arrErrs []error
for err := range errors {
if err != nil {
arrErrs = append(arrErrs, err)
}
}
return multierr.Combine(arrErrs...)
}
func isDBConnectionError(err error) bool {
if _, ok := err.(net.Error); ok {
return ok
}
if _, ok := err.(*net.OpError); ok {
return ok
}
return false
}