File size: 771 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
package message
import "time"
// ThrottleRule sets the number of messages allowed to be sent per set duration.
type ThrottleRule struct {
Count int
Per time.Duration
// Smooth indicates that the rule should impose a rate limit over the entire duration.
Smooth bool
}
// ThrottleRules is a collection of ThrottleRule that implements the ThrottleConfig interface.
type ThrottleRules []ThrottleRule
// Rules always returns the set of configured rules for all messages.
func (rs ThrottleRules) Rules(Message) []ThrottleRule { return rs }
// MaxDuration returns the longest `Per` value for the set of rules.
func (rs ThrottleRules) MaxDuration() time.Duration {
var dur time.Duration
for _, r := range rs {
if r.Per > dur {
dur = r.Per
}
}
return dur
}
|