dingtalkrus

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 13 Imported by: 0

README

dingtalkrus

DingTalk Hook for Logrus.

Use
package main

import (
	"github.com/leafney/dingtalkrus"
	"github.com/sirupsen/logrus"
	"os"
)

func main() {
	logrus.SetFormatter(&logrus.JSONFormatter{})

	logrus.SetOutput(os.Stderr)

	logrus.SetLevel(logrus.DebugLevel)

	logrus.AddHook(dingtalkrus.NewHook(
		"", // dingtalk token
		"", // dingtalk secret
		dingtalkrus.LevelThreshold(logrus.ErrorLevel)),
	)

	logrus.Info("This is the info test message.")
	logrus.WithFields(dingtalkrus.SendTextMsg("This is the warn test message.",[]string{},false)).Warn()
	logrus.WithFields(dingtalkrus.SendMarkdownMsg("杭州天气","#### 杭州天气 \n 9度,西北风1级,空气良89,相对温度73%\n",[]string{},false)).Error()
}
Installation
go get github.com/leafney/dingtalkrus
Message parameters

SendTextMsg

参数 参数类型 必须 说明
content String 消息内容
atMobiles Array 被@人的手机号(在content里添加@人的手机号)
isAtAll Boolean 是否@所有人

SendMarkdownMsg

参数 参数类型 必须 说明
title String 首屏会话透出的展示内容
text String markdown格式的消息
atMobiles Array 被@人的手机号(在text内容里需要有@手机号)
isAtAll Boolean 是否@所有人

SendLinkMsg

参数 参数类型 必须 说明
title String 消息标题
text String 是 消息内容。如果太长只会部分展示
messageUrl String 点击消息跳转的URL
picUrl String 图片URL
Reference

Documentation

Index

Constants

This section is empty.

Variables

Supported log levels

Functions

func LevelThreshold

func LevelThreshold(l logrus.Level) []logrus.Level

Returns every logging level above and including the given parameter.

func SendLinkMsg

func SendLinkMsg(title string, text string, messageUrl string, picUrl string) logrus.Fields

func SendMarkdownMsg

func SendMarkdownMsg(title string, text string, atMobiles []string, isAtAll bool) logrus.Fields

func SendTextMsg

func SendTextMsg(content string, atMobiles []string, isAtAll bool) logrus.Fields

Types

type DingTalkHook

type DingTalkHook struct {
	Token        string
	Secret       string
	AcceptLevels []logrus.Level
}

func NewHook

func NewHook(token string, secret string, levels []logrus.Level) *DingTalkHook

func (*DingTalkHook) Fire

func (dh *DingTalkHook) Fire(entry *logrus.Entry) error

func (*DingTalkHook) Levels

func (dh *DingTalkHook) Levels() []logrus.Level

type DingTalkResponse

type DingTalkResponse struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

Jump to

Keyboard shortcuts

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