summaryrefslogtreecommitdiff
path: root/internal/easyhttp/saferrors.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-07-03 11:27:40 +0300
committerPaul Buetow <paul@buetow.org>2024-07-03 11:27:40 +0300
commit4bde5943fa9bee99e8ad1e570d05e142cbacade7 (patch)
tree0d44100242131705a72d342724d825abc9d088f8 /internal/easyhttp/saferrors.go
parentd7987e74ea89a6803a3de4fd97104474bdd949bf (diff)
add safe errors
Diffstat (limited to 'internal/easyhttp/saferrors.go')
-rw-r--r--internal/easyhttp/saferrors.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/easyhttp/saferrors.go b/internal/easyhttp/saferrors.go
new file mode 100644
index 0000000..32dd77f
--- /dev/null
+++ b/internal/easyhttp/saferrors.go
@@ -0,0 +1,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()
+}