优化结构

This commit is contained in:
Yvan
2026-08-28 00:29:40 +08:00
parent 04ff85116c
commit 03a4131f6e
118 changed files with 758 additions and 834 deletions
-20
View File
@@ -9,7 +9,6 @@ import (
type EmailRepo interface {
Send(context.Context, []string, string, string) error
DefaultRecipients() []string
Enabled() bool
}
type EmailUsecase struct{ repo EmailRepo }
@@ -27,22 +26,3 @@ func (uc *EmailUsecase) Test(ctx context.Context) error {
}
return uc.repo.Send(ctx, recipients, "test", "test")
}
func (uc *EmailUsecase) Alert(ctx context.Context, subject, body string) error {
if !uc.repo.Enabled() {
return nil
}
// ErrorToEmail splits the configured comma-separated recipient
// string, while its explicit test endpoint deliberately sends the whole
// value as one recipient. Keep those two contracts separate.
configured := uc.repo.DefaultRecipients()
recipients := make([]string, 0, len(configured))
for _, value := range configured {
parts := strings.Split(value, ",")
if len(parts) > 1 && parts[len(parts)-1] == "" {
parts = parts[:len(parts)-1]
}
recipients = append(recipients, parts...)
}
return uc.repo.Send(ctx, recipients, subject, body)
}