mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
So we don't have to worry about network stack changes causes an upstream to be broken. Just send requests to all nameservers concurrently, and get the first success response.
44 lines
640 B
Go
44 lines
640 B
Go
package ctrld
|
|
|
|
// TODO(cuonglm): use stdlib once we bump minimum version to 1.20
|
|
|
|
func joinErrors(errs ...error) error {
|
|
n := 0
|
|
for _, err := range errs {
|
|
if err != nil {
|
|
n++
|
|
}
|
|
}
|
|
if n == 0 {
|
|
return nil
|
|
}
|
|
e := &joinError{
|
|
errs: make([]error, 0, n),
|
|
}
|
|
for _, err := range errs {
|
|
if err != nil {
|
|
e.errs = append(e.errs, err)
|
|
}
|
|
}
|
|
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
|
|
}
|