mirror of
https://github.com/usual2970/certimate.git
synced 2025-08-13 21:01:45 +00:00
.github
.vscode
docker
internal
app
applicant
certificate
deployer
domain
notify
notify.go
providers.go
service.go
pkg
repository
rest
scheduler
statistics
workflow
migrations
ui
.dockerignore
.editorconfig
.gitignore
.goreleaser.yml
CHANGELOG.md
CONTRIBUTING.md
CONTRIBUTING_EN.md
Dockerfile
LICENSE.md
Makefile
README.md
README_EN.md
go.mod
go.sum
main.go
nixpacks.toml
usage.gif
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package notify
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/usual2970/certimate/internal/domain"
|
|
"github.com/usual2970/certimate/internal/domain/dtos"
|
|
)
|
|
|
|
const (
|
|
notifyTestTitle = "测试通知"
|
|
notifyTestBody = "欢迎使用 Certimate ,这是一条测试通知。"
|
|
)
|
|
|
|
type settingsRepository interface {
|
|
GetByName(ctx context.Context, name string) (*domain.Settings, error)
|
|
}
|
|
|
|
type NotifyService struct {
|
|
settingsRepo settingsRepository
|
|
}
|
|
|
|
func NewNotifyService(settingsRepo settingsRepository) *NotifyService {
|
|
return &NotifyService{
|
|
settingsRepo: settingsRepo,
|
|
}
|
|
}
|
|
|
|
func (n *NotifyService) Test(ctx context.Context, req *dtos.NotifyTestPushReq) error {
|
|
settings, err := n.settingsRepo.GetByName(ctx, "notifyChannels")
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get notify channels settings: %w", err)
|
|
}
|
|
|
|
channelConfig, err := settings.GetNotifyChannelConfig(string(req.Channel))
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get notify channel \"%s\" config: %w", req.Channel, err)
|
|
}
|
|
|
|
return SendToChannel(notifyTestTitle, notifyTestBody, string(req.Channel), channelConfig)
|
|
}
|