wxalarm

package
v0.0.0-...-6d34543 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WxHookKey          = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send"
	WxErrCodeFreqLimit = 45009
)

Variables

View Source
var (
	AlarmTemplate = `
异常消息:
- 环境: %s
- 服务名称: %s
- 消息IP: %s
- 消息时间: %s
- 提示: %s
- 错误信息: %v`
)

Functions

This section is empty.

Types

type Config

type Config struct {
	WebHook  string `json:"web_hook"`
	Retries  int    `json:"retries"`
	Interval int    `json:"interval"` // second
}

type Option

type Option func(*WXAlarm)

func WithConf

func WithConf(conf config.Config) Option

func WithLogger

func WithLogger(logger log.Logger) Option

type Output

type Output struct {
	ErrCode int    `json:"err_code"`
	ErrMsg  string `json:"err_msg"`
}

type WXAlarm

type WXAlarm struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *WXAlarm

func (*WXAlarm) SendMarkdownMessage

func (w *WXAlarm) SendMarkdownMessage(ctx context.Context, message string) (*Output, error)

发送markdown形式消息

func (*WXAlarm) SendMarkdownMessageWithRetry

func (w *WXAlarm) SendMarkdownMessageWithRetry(ctx context.Context, message string) (output *Output, err error)

发送失败进行重试,只限于网络报错或者频率限制错误进行重试 谨慎使用,该函数会阻塞调用

func (*WXAlarm) SendMessage

func (w *WXAlarm) SendMessage(ctx context.Context, message string) (*Output, error)

func (*WXAlarm) SendTextMessage

func (w *WXAlarm) SendTextMessage(ctx context.Context, message string, mentionedList, MentionedMobileList []string) (*Output, error)

发送text形式消息

func (*WXAlarm) SendTextMessageWithRetry

func (w *WXAlarm) SendTextMessageWithRetry(ctx context.Context, message string, mentionedList, MentionedMobileList []string) (output *Output, err error)

发送失败进行重试,只限于网络报错或者频率限制错误进行重试 谨慎使用,该函数会阻塞调用

Jump to

Keyboard shortcuts

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