summaryrefslogtreecommitdiff
path: root/teleirc/matterbridge/vendor/github.com/wiggin77/merror
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-11-02 15:27:18 +0800
committerMistivia <i@mistivia.com>2025-11-02 15:27:18 +0800
commite9c24f4af7ed56760f6db7941827d09f6db9020b (patch)
tree62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/vendor/github.com/wiggin77/merror
parent58d5e7cfda4781d8a57ec52aefd02983835c301a (diff)
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/vendor/github.com/wiggin77/merror')
-rw-r--r--teleirc/matterbridge/vendor/github.com/wiggin77/merror/.gitignore12
-rw-r--r--teleirc/matterbridge/vendor/github.com/wiggin77/merror/.travis.yml5
-rw-r--r--teleirc/matterbridge/vendor/github.com/wiggin77/merror/LICENSE21
-rw-r--r--teleirc/matterbridge/vendor/github.com/wiggin77/merror/README.md6
-rw-r--r--teleirc/matterbridge/vendor/github.com/wiggin77/merror/format.go43
-rw-r--r--teleirc/matterbridge/vendor/github.com/wiggin77/merror/merror.go120
6 files changed, 207 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/github.com/wiggin77/merror/.gitignore b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/.gitignore
new file mode 100644
index 0000000..f1c181e
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/.gitignore
@@ -0,0 +1,12 @@
+# Binaries for programs and plugins
+*.exe
+*.exe~
+*.dll
+*.so
+*.dylib
+
+# Test binary, build with `go test -c`
+*.test
+
+# Output of the go coverage tool, specifically when used with LiteIDE
+*.out
diff --git a/teleirc/matterbridge/vendor/github.com/wiggin77/merror/.travis.yml b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/.travis.yml
new file mode 100644
index 0000000..9899b38
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/.travis.yml
@@ -0,0 +1,5 @@
+language: go
+sudo: false
+before_script:
+ - go vet ./...
+ \ No newline at end of file
diff --git a/teleirc/matterbridge/vendor/github.com/wiggin77/merror/LICENSE b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/LICENSE
new file mode 100644
index 0000000..2b0bf7e
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 wiggin77
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/teleirc/matterbridge/vendor/github.com/wiggin77/merror/README.md b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/README.md
new file mode 100644
index 0000000..964c7ac
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/README.md
@@ -0,0 +1,6 @@
+# merror
+
+[![GoDoc](https://godoc.org/github.com/wiggin77/merror?status.svg)](https://godoc.org/github.com/wiggin77/merror)
+[![Build Status](https://travis-ci.org/wiggin77/merror.svg?branch=master)](https://travis-ci.org/wiggin77/merror)
+
+Multiple Error aggregator for Go.
diff --git a/teleirc/matterbridge/vendor/github.com/wiggin77/merror/format.go b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/format.go
new file mode 100644
index 0000000..8ba9aa8
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/format.go
@@ -0,0 +1,43 @@
+package merror
+
+import (
+ "fmt"
+ "strings"
+)
+
+// FormatterFunc is a function that converts a merror
+// to a string.
+type FormatterFunc func(merr *MError) string
+
+// GlobalFormatter is the global merror formatter.
+// Set this to a custom formatter if desired.
+var GlobalFormatter = defaultFormatter
+
+// defaultFormatter
+func defaultFormatter(merr *MError) string {
+ count := 0
+ overflow := 0
+
+ var format func(sb *strings.Builder, merr *MError, indent string)
+ format = func(sb *strings.Builder, merr *MError, indent string) {
+ count += merr.Len()
+ overflow += merr.Overflow()
+
+ fmt.Fprintf(sb, "%sMError:\n", indent)
+ for _, err := range merr.Errors() {
+ if e, ok := err.(*MError); ok {
+ format(sb, e, indent+" ")
+ } else {
+ fmt.Fprintf(sb, "%s%s\n", indent, err.Error())
+ }
+ }
+ }
+
+ sb := &strings.Builder{}
+ format(sb, merr, "")
+ fmt.Fprintf(sb, "%d errors total.\n", count)
+ if merr.overflow > 0 {
+ fmt.Fprintf(sb, "%d errors truncated.\n", overflow)
+ }
+ return sb.String()
+}
diff --git a/teleirc/matterbridge/vendor/github.com/wiggin77/merror/merror.go b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/merror.go
new file mode 100644
index 0000000..def7535
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/wiggin77/merror/merror.go
@@ -0,0 +1,120 @@
+package merror
+
+import "sync"
+
+// MError represents zero or more errors that can be
+// accumulated via the `Append` method.
+type MError struct {
+ cap int
+
+ mux sync.RWMutex
+ errors []error
+ overflow int
+ formatter FormatterFunc
+}
+
+// New returns a new instance of `MError` with no limit on the
+// number of errors that can be appended.
+func New() *MError {
+ me := &MError{}
+ me.errors = make([]error, 0, 10)
+ return me
+}
+
+// NewWithCap returns a new instance of `MError` with a maximum
+// capacity of `cap` errors. If exceeded only the overflow counter
+// will be incremented.
+//
+// A `cap` of zero of less means no cap and max size of a slice
+// on the current platform is the upper bound.
+func NewWithCap(cap int) *MError {
+ me := New()
+ me.cap = cap
+ return me
+}
+
+// Append adds an error to the aggregated error list.
+func (me *MError) Append(err error) {
+ if err == nil {
+ return
+ }
+
+ me.mux.Lock()
+ defer me.mux.Unlock()
+
+ if me.cap > 0 && len(me.errors) >= me.cap {
+ me.overflow++
+ } else {
+ me.errors = append(me.errors, err)
+ }
+}
+
+// Errors returns a slice of the `error` instances that have been
+// appended to this `MError`.
+func (me *MError) Errors() []error {
+ me.mux.RLock()
+ defer me.mux.RUnlock()
+
+ errs := make([]error, len(me.errors))
+ copy(errs, me.errors)
+
+ return errs
+}
+
+// Len returns the number of errors that have been appended.
+func (me *MError) Len() int {
+ me.mux.RLock()
+ defer me.mux.RUnlock()
+
+ return len(me.errors)
+}
+
+// Overflow returns the number of errors that have been truncated
+// because maximum capacity was exceeded.
+func (me *MError) Overflow() int {
+ me.mux.RLock()
+ defer me.mux.RUnlock()
+
+ return me.overflow
+}
+
+// SetFormatter sets the `FormatterFunc` to be used when `Error` is
+// called. The previous `FormatterFunc` is returned.
+func (me *MError) SetFormatter(f FormatterFunc) (old FormatterFunc) {
+ me.mux.Lock()
+ defer me.mux.Unlock()
+
+ old = me.formatter
+ me.formatter = f
+ return
+}
+
+// ErrorOrNil returns nil if this `MError` contains no errors,
+// otherwise this `MError` is returned.
+func (me *MError) ErrorOrNil() error {
+ if me == nil {
+ return nil
+ }
+
+ me.mux.RLock()
+ defer me.mux.RUnlock()
+
+ if len(me.errors) == 0 {
+ return nil
+ }
+ return me
+}
+
+// Error returns a string representation of this MError.
+// The output format depends on the `Formatter` set for this
+// merror instance, or the global formatter if none set.
+func (me *MError) Error() string {
+ me.mux.RLock()
+ defer me.mux.RUnlock()
+
+ f := me.formatter
+ if f == nil {
+ f = GlobalFormatter
+ }
+ return f(me)
+}