dingtalk

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

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

func NewDingTalkNotifier

func NewDingTalkNotifier(logger log.Logger, receivers []config.Receiver, notifierCfg *config.Config) notifier.Notifier

Types

type Notifier

type Notifier struct {
	DingTalk []*config.DingTalk
	// contains filtered or unexported fields
}

func (*Notifier) Notify

func (n *Notifier) Notify(ctx context.Context, data template.Data) []error

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

func (t *Throttle) Allow(key string, logger log.Logger) bool

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`.

func (*Throttle) Get

func (t *Throttle) Get(url string) *rateLimiter

func (*Throttle) TryAdd

func (t *Throttle) TryAdd(key string, threshold int, unitTime time.Duration, maxWaitTime time.Duration)

TryAdd rateLimiter, if exist, do nothing

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL