summaryrefslogtreecommitdiff
path: root/internal/easyhttp/saferrors.go
blob: 464c90d803810b4771b39b97e0a7b6887fbd8835 (plain)
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
package easyhttp

import (
	"errors"
	"sync"
)

// Safe errors
type safErrors struct {
	errs  []error
	mutex sync.Mutex
}

func (errs *safErrors) Append(err error) {
	if err == nil {
		return
	}
	errs.mutex.Lock()
	defer errs.mutex.Unlock()
	errs.errs = append(errs.errs, err)
}

func (errs *safErrors) Join() error {
	errs.mutex.Lock()
	defer errs.mutex.Unlock()
	return errors.Join(errs.errs...)
}

func (errs *safErrors) Error() string {
	return errs.Join().Error()
}