summaryrefslogtreecommitdiff
path: root/internal/gtserror/multi.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-08-04 12:28:33 +0100
committerLibravatar GitHub <noreply@github.com>2023-08-04 12:28:33 +0100
commit9a291dea843448f78b4b98ea6813739aebe708c6 (patch)
treef1ce643a3c9fe1b13e4c107f15b1ac4b20fe5b86 /internal/gtserror/multi.go
parent[feature] simpler cache size configuration (#2051) (diff)
downloadgotosocial-9a291dea843448f78b4b98ea6813739aebe708c6.tar.xz
[performance] add caching of status fave, boost of, in reply to ID lists (#2060)
Diffstat (limited to 'internal/gtserror/multi.go')
-rw-r--r--internal/gtserror/multi.go18
1 files changed, 7 insertions, 11 deletions
diff --git a/internal/gtserror/multi.go b/internal/gtserror/multi.go
index 1c533b285..3d39333b6 100644
--- a/internal/gtserror/multi.go
+++ b/internal/gtserror/multi.go
@@ -19,16 +19,13 @@ package gtserror
import (
"errors"
- "fmt"
)
// MultiError allows encapsulating multiple
// errors under a singular instance, which
// is useful when you only want to log on
// errors, not return early / bubble up.
-type MultiError struct {
- e []error
-}
+type MultiError []error
// NewMultiError returns a *MultiError with
// the capacity of its underlying error slice
@@ -40,15 +37,13 @@ type MultiError struct {
//
// If you don't know in advance what the capacity
// must be, just use new(MultiError) instead.
-func NewMultiError(capacity int) *MultiError {
- return &MultiError{
- e: make([]error, 0, capacity),
- }
+func NewMultiError(capacity int) MultiError {
+ return make([]error, 0, capacity)
}
// Append the given error to the MultiError.
func (m *MultiError) Append(err error) {
- m.e = append(m.e, err)
+ (*m) = append((*m), err)
}
// Append the given format string to the MultiError.
@@ -56,12 +51,13 @@ func (m *MultiError) Append(err error) {
// It is valid to use %w in the format string
// to wrap any other errors.
func (m *MultiError) Appendf(format string, args ...any) {
- m.e = append(m.e, fmt.Errorf(format, args...))
+ err := newfAt(3, format, args...)
+ (*m) = append((*m), err)
}
// Combine the MultiError into a single error.
//
// Unwrap will work on the returned error as expected.
func (m MultiError) Combine() error {
- return errors.Join(m.e...)
+ return errors.Join(m...)
}