summaryrefslogtreecommitdiff
path: root/teleirc/matterbridge/vendor/github.com/slack-go/slack/internal
diff options
context:
space:
mode:
Diffstat (limited to 'teleirc/matterbridge/vendor/github.com/slack-go/slack/internal')
-rw-r--r--teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/backoff/backoff.go62
-rw-r--r--teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/errorsx/errorsx.go17
-rw-r--r--teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/timex/timex.go18
3 files changed, 97 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/backoff/backoff.go b/teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/backoff/backoff.go
new file mode 100644
index 0000000..833e9f2
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/backoff/backoff.go
@@ -0,0 +1,62 @@
+package backoff
+
+import (
+ "math/rand"
+ "time"
+)
+
+// This one was ripped from https://github.com/jpillora/backoff/blob/master/backoff.go
+
+// Backoff is a time.Duration counter. It starts at Min. After every
+// call to Duration() it is multiplied by Factor. It is capped at
+// Max. It returns to Min on every call to Reset(). Used in
+// conjunction with the time package.
+type Backoff struct {
+ attempts int
+ // Initial value to scale out
+ Initial time.Duration
+ // Jitter value randomizes an additional delay between 0 and Jitter
+ Jitter time.Duration
+ // Max maximum values of the backoff
+ Max time.Duration
+}
+
+// Returns the current value of the counter and then multiplies it
+// Factor
+func (b *Backoff) Duration() (dur time.Duration) {
+ // Zero-values are nonsensical, so we use
+ // them to apply defaults
+ if b.Max == 0 {
+ b.Max = 10 * time.Second
+ }
+
+ if b.Initial == 0 {
+ b.Initial = 100 * time.Millisecond
+ }
+
+ // calculate this duration
+ if dur = time.Duration(1 << uint(b.attempts)); dur > 0 {
+ dur = dur * b.Initial
+ } else {
+ dur = b.Max
+ }
+
+ if b.Jitter > 0 {
+ dur = dur + time.Duration(rand.Intn(int(b.Jitter)))
+ }
+
+ // bump attempts count
+ b.attempts++
+
+ return dur
+}
+
+// Resets the current value of the counter back to Min
+func (b *Backoff) Reset() {
+ b.attempts = 0
+}
+
+// Attempts returns the number of attempts that we had done so far
+func (b *Backoff) Attempts() int {
+ return b.attempts
+}
diff --git a/teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/errorsx/errorsx.go b/teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/errorsx/errorsx.go
new file mode 100644
index 0000000..0182ec6
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/errorsx/errorsx.go
@@ -0,0 +1,17 @@
+package errorsx
+
+// String representing an error, useful for declaring string constants as errors.
+type String string
+
+func (t String) Error() string {
+ return string(t)
+}
+
+// Is reports whether String matches with the target error
+func (t String) Is(target error) bool {
+ if target == nil {
+ return false
+ }
+
+ return t.Error() == target.Error()
+}
diff --git a/teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/timex/timex.go b/teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/timex/timex.go
new file mode 100644
index 0000000..40063f7
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/slack-go/slack/internal/timex/timex.go
@@ -0,0 +1,18 @@
+package timex
+
+import "time"
+
+// Max returns the maximum duration
+func Max(values ...time.Duration) time.Duration {
+ var (
+ max time.Duration
+ )
+
+ for _, v := range values {
+ if v > max {
+ max = v
+ }
+ }
+
+ return max
+}