one-api/common/notify/send.go
Buer a3719cd78a
feat: add notifier (#144)
* ♻️ refactor: email refactor

*  feat: add notifier
2024-04-09 15:00:06 +08:00

31 lines
650 B
Go

package notify
import (
"context"
"fmt"
"one-api/common"
)
func (n *Notify) Send(ctx context.Context, title, message string) {
if ctx == nil {
ctx = context.Background()
}
for channelName, channel := range n.notifiers {
if channel == nil {
continue
}
err := channel.Send(ctx, title, message)
if err != nil {
common.LogError(ctx, fmt.Sprintf("%s err: %s", channelName, err.Error()))
}
}
}
func Send(title, message string) {
//lint:ignore SA1029 reason: 需要使用该类型作为错误处理
ctx := context.WithValue(context.Background(), common.RequestIdKey, "NotifyTask")
notifyChannels.Send(ctx, title, message)
}