diff options
author | Wim <wim@42.be> | 2021-02-01 21:29:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-01 21:29:04 +0100 |
commit | 0452be0cb383ff560e340b643b60a35c6e228639 (patch) | |
tree | 41b91af43c2e321d6498a6b56594b1d0c71c516e /vendor/github.com/slack-go/slack/internal | |
parent | 1624f107739b8ed7b142732430e5295764388de2 (diff) | |
download | matterbridge-msglm-0452be0cb383ff560e340b643b60a35c6e228639.tar.gz matterbridge-msglm-0452be0cb383ff560e340b643b60a35c6e228639.tar.bz2 matterbridge-msglm-0452be0cb383ff560e340b643b60a35c6e228639.zip |
Update vendor (#1384)
Diffstat (limited to 'vendor/github.com/slack-go/slack/internal')
-rw-r--r-- | vendor/github.com/slack-go/slack/internal/backoff/backoff.go | 62 | ||||
-rw-r--r-- | vendor/github.com/slack-go/slack/internal/misc/misc.go | 28 |
2 files changed, 90 insertions, 0 deletions
diff --git a/vendor/github.com/slack-go/slack/internal/backoff/backoff.go b/vendor/github.com/slack-go/slack/internal/backoff/backoff.go new file mode 100644 index 00000000..df210f80 --- /dev/null +++ b/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/vendor/github.com/slack-go/slack/internal/misc/misc.go b/vendor/github.com/slack-go/slack/internal/misc/misc.go new file mode 100644 index 00000000..eab8cdd8 --- /dev/null +++ b/vendor/github.com/slack-go/slack/internal/misc/misc.go @@ -0,0 +1,28 @@ +package misc + +import ( + "fmt" + "net/http" +) + +// StatusCodeError represents an http response error. +// type httpStatusCode interface { HTTPStatusCode() int } to handle it. +type StatusCodeError struct { + Code int + Status string +} + +func (t StatusCodeError) Error() string { + return fmt.Sprintf("slack server error: %s", t.Status) +} + +func (t StatusCodeError) HTTPStatusCode() int { + return t.Code +} + +func (t StatusCodeError) Retryable() bool { + if t.Code >= 500 || t.Code == http.StatusTooManyRequests { + return true + } + return false +} |