Documentation ¶
Index ¶
- Constants
- func NewDingTalkNotifier(logger log.Logger, receivers []config.Receiver, notifierCfg *config.Config) notifier.Notifier
- type Notifier
- type Throttle
- func (t *Throttle) Add(key string, threshold int, unitTime time.Duration, maxWaitTime time.Duration)
- func (t *Throttle) Allow(key string, logger log.Logger) bool
- func (t *Throttle) Get(url string) *rateLimiter
- func (t *Throttle) TryAdd(key string, threshold int, unitTime time.Duration, maxWaitTime time.Duration)
Constants ¶
View Source
const ( URL = "https://oapi.dingtalk.com/" DefaultSendTimeout = time.Second * 3 DefaultTextTemplate = `{{ template "nm.default.text" . }}` DefaultTitleTemplate = `{{ template "nm.default.subject" . }}` DefaultMarkdownTemplate = `{{ template "nm.default.markdown" . }}` ConversationMessageMaxSize = 5000 ChatbotMessageMaxSize = 19960 DefaultExpires = time.Hour * 2 DefaultChatbotThreshold = 20 DefaultChatbotUnit = time.Minute DefaultChatbotWaitTime = time.Second * 10 DefaultConversationThreshold = 25 DefaultConversationUnit = time.Second )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Throttle ¶
type Throttle struct {
// contains filtered or unexported fields
}
func GetThrottle ¶
func GetThrottle() *Throttle
func (*Throttle) Add ¶
func (t *Throttle) Add(key string, threshold int, unitTime time.Duration, maxWaitTime time.Duration)
Add rateLimiter, if exist, update
func (*Throttle) Allow ¶
Allow calculates whether the api calls reaches the flow limit, if not, return true, otherwise wait for the flow limit to be lifted, and return true. The max waiting time is set by `maxWaitTime`, if the actual waiting time is more than `maxWaitTime`, it will not wait, and return false.
The `threshold` defines the allowed calls per `unitTime`. The queue stores the time of the last (threshold - 1) call.
The logic of flow control is that the time of any `threshold` consecutive calls cannot be greater than `unitTime`.
Click to show internal directories.
Click to hide internal directories.