Merge branch 'main' into feat/aws

This commit is contained in:
Fu Diwei
2024-10-17 18:27:01 +08:00
10 changed files with 200 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
package notify
import (
"certimate/internal/utils/app"
"context"
"fmt"
"strconv"
@@ -8,15 +9,15 @@ import (
notifyPackage "github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/dingding"
"github.com/nikoksr/notify/service/http"
"github.com/nikoksr/notify/service/lark"
"github.com/nikoksr/notify/service/telegram"
"certimate/internal/utils/app"
)
const (
notifyChannelDingtalk = "dingtalk"
notifyChannelWebhook = "webhook"
notifyChannelTelegram = "telegram"
notifyChannelLark = "lark"
)
func Send(title, content string) error {
@@ -67,6 +68,8 @@ func getNotifiers() ([]notifyPackage.Notifier, error) {
notifiers = append(notifiers, temp)
case notifyChannelDingtalk:
notifiers = append(notifiers, getDingTalkNotifier(v))
case notifyChannelLark:
notifiers = append(notifiers, getLarkNotifier(v))
case notifyChannelWebhook:
notifiers = append(notifiers, getWebhookNotifier(v))
}
@@ -108,6 +111,10 @@ func getDingTalkNotifier(conf map[string]any) notifyPackage.Notifier {
})
}
func getLarkNotifier(conf map[string]any) notifyPackage.Notifier {
return lark.NewWebhookService(getString(conf, "webhookUrl"))
}
func getString(conf map[string]any, key string) string {
if _, ok := conf[key]; !ok {
return ""