mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-27 00:51:55 +08:00
release revsuit vBeta0.1.0 (#15)
Co-authored-by: E99p1ant <[email protected]>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/li4n0/revsuit/internal/record"
|
||||
"github.com/pkg/errors"
|
||||
log "unknwon.dev/clog/v2"
|
||||
)
|
||||
|
||||
@@ -14,6 +15,7 @@ var (
|
||||
|
||||
// Bot is used to send notice
|
||||
type Bot interface {
|
||||
name() string
|
||||
notice(record.Record) error
|
||||
buildPayload(record.Record) string
|
||||
}
|
||||
@@ -41,7 +43,7 @@ func (a *Announcer) AddBot(b Bot) *Announcer {
|
||||
func Notice(r record.Record) {
|
||||
for _, bot := range announcer.Bots {
|
||||
if err := bot.notice(r); err != nil {
|
||||
log.Warn(err.Error())
|
||||
log.Warn(errors.Wrap(err, "%s notice failed").Error(), bot.name())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ type dingPayload struct {
|
||||
At []dingAt `json:"at"`
|
||||
}
|
||||
|
||||
func (d *DingTalk) name() string {
|
||||
return "DingTalk"
|
||||
}
|
||||
|
||||
func (d *DingTalk) buildPayload(r record.Record) string {
|
||||
payload := dingPayload{
|
||||
MsgType: "markdown",
|
||||
|
||||
@@ -41,7 +41,11 @@ type larkPayload struct {
|
||||
Card larkCard `json:"card"`
|
||||
}
|
||||
|
||||
func (d *Lark) buildPayload(r record.Record) string {
|
||||
func (l *Lark) name() string {
|
||||
return "Lark"
|
||||
}
|
||||
|
||||
func (l *Lark) buildPayload(r record.Record) string {
|
||||
payload := larkPayload{
|
||||
MsgType: "interactive",
|
||||
Card: larkCard{
|
||||
@@ -69,8 +73,8 @@ func (d *Lark) buildPayload(r record.Record) string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (d *Lark) notice(r record.Record) error {
|
||||
resp, err := http.Post(d.URL, "application/json", strings.NewReader(d.buildPayload(r)))
|
||||
func (l *Lark) notice(r record.Record) error {
|
||||
resp, err := http.Post(l.URL, "application/json", strings.NewReader(l.buildPayload(r)))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "HTTP request")
|
||||
}
|
||||
|
||||
@@ -36,7 +36,11 @@ type slackPayload struct {
|
||||
Attachments []slackAttachments `json:"attachments"`
|
||||
}
|
||||
|
||||
func (d *Slack) buildPayload(r record.Record) string {
|
||||
func (s *Slack) name() string {
|
||||
return "Slack"
|
||||
}
|
||||
|
||||
func (s *Slack) buildPayload(r record.Record) string {
|
||||
payload := slackPayload{
|
||||
Attachments: []slackAttachments{
|
||||
{
|
||||
@@ -67,8 +71,8 @@ func (d *Slack) buildPayload(r record.Record) string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (d *Slack) notice(r record.Record) error {
|
||||
resp, err := http.Post(d.URL, "application/json", strings.NewReader(d.buildPayload(r)))
|
||||
func (s *Slack) notice(r record.Record) error {
|
||||
resp, err := http.Post(s.URL, "application/json", strings.NewReader(s.buildPayload(r)))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "HTTP request")
|
||||
}
|
||||
|
||||
@@ -27,6 +27,10 @@ type weixinPayload struct {
|
||||
Markdown weixinMarkdown `json:"markdown"`
|
||||
}
|
||||
|
||||
func (w *Weixin) name() string {
|
||||
return "Weixin"
|
||||
}
|
||||
|
||||
func (w *Weixin) buildPayload(r record.Record) string {
|
||||
payload := weixinPayload{
|
||||
ToUser: "@all",
|
||||
|
||||
Reference in New Issue
Block a user