* INFRA-2887 : SLA breach heads up cron refactor/reimplementation * INFRA-2887 : Code review comments
38 lines
658 B
Go
38 lines
658 B
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
type ThreadSafeErrors struct {
|
|
mutex sync.Mutex
|
|
errors []error
|
|
}
|
|
|
|
func (errs *ThreadSafeErrors) AddErrors(errsToAdd ...error) {
|
|
errs.mutex.Lock()
|
|
defer errs.mutex.Unlock()
|
|
errs.errors = append(errs.errors, errsToAdd...)
|
|
}
|
|
|
|
func (errs *ThreadSafeErrors) GetErrors() []error {
|
|
return errs.errors
|
|
}
|
|
|
|
func (errs *ThreadSafeErrors) CollectErrors() error {
|
|
if len(errs.errors) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var errorStrings []string
|
|
for _, err := range errs.errors {
|
|
if err != nil {
|
|
errorStrings = append(errorStrings, err.Error())
|
|
}
|
|
}
|
|
|
|
return fmt.Errorf("%s", strings.Join(errorStrings, "; "))
|
|
}
|