mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-26 00:33:03 +02:00
Attachment behavior fix for Firefox
This commit is contained in:
parent
f98743dd9b
commit
aba7e86cbc
13 changed files with 223 additions and 123 deletions
util
|
@ -15,6 +15,10 @@ var ErrLimitReached = errors.New("limit reached")
|
|||
type Limiter interface {
|
||||
// Allow adds n to the limiters internal value, or returns ErrLimitReached if the limit has been reached
|
||||
Allow(n int64) error
|
||||
|
||||
// Remaining returns the remaining count until the limit is reached; may return -1 if the implementation
|
||||
// does not support this operation.
|
||||
Remaining() int64
|
||||
}
|
||||
|
||||
// FixedLimiter is a helper that allows adding values up to a well-defined limit. Once the limit is reached
|
||||
|
@ -44,6 +48,13 @@ func (l *FixedLimiter) Allow(n int64) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Remaining returns the remaining count until the limit is reached
|
||||
func (l *FixedLimiter) Remaining() int64 {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.limit - l.value
|
||||
}
|
||||
|
||||
// RateLimiter is a Limiter that wraps a rate.Limiter, allowing a floating time-based limit.
|
||||
type RateLimiter struct {
|
||||
limiter *rate.Limiter
|
||||
|
@ -74,6 +85,11 @@ func (l *RateLimiter) Allow(n int64) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Remaining is not implemented for RateLimiter. It always returns -1.
|
||||
func (l *RateLimiter) Remaining() int64 {
|
||||
return -1
|
||||
}
|
||||
|
||||
// LimitWriter implements an io.Writer that will pass through all Write calls to the underlying
|
||||
// writer w until any of the limiter's limit is reached, at which point a Write will return ErrLimitReached.
|
||||
// Each limiter's value is increased with every write.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue