mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-09 05:59:50 +00:00
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package notify
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/usual2970/certimate/internal/domain"
|
|
)
|
|
|
|
const (
|
|
notifyTestTitle = "测试通知"
|
|
notifyTestBody = "欢迎使用 Certimate ,这是一条测试通知。"
|
|
)
|
|
|
|
type SettingsRepository interface {
|
|
GetByName(ctx context.Context, name string) (*domain.Settings, error)
|
|
}
|
|
|
|
type NotifyService struct {
|
|
settingRepo SettingsRepository
|
|
}
|
|
|
|
func NewNotifyService(settingRepo SettingsRepository) *NotifyService {
|
|
return &NotifyService{
|
|
settingRepo: settingRepo,
|
|
}
|
|
}
|
|
|
|
func (n *NotifyService) Test(ctx context.Context, req *domain.NotifyTestPushReq) error {
|
|
setting, err := n.settingRepo.GetByName(ctx, "notifyChannels")
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get notify channels settings: %w", err)
|
|
}
|
|
|
|
channelConfig, err := setting.GetNotifyChannelConfig(req.Channel)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get notify channel \"%s\" config: %w", req.Channel, err)
|
|
}
|
|
|
|
return SendToChannel(notifyTestTitle, notifyTestBody, req.Channel, channelConfig)
|
|
}
|