refactor: clean code

This commit is contained in:
Fu Diwei
2025-05-28 22:43:18 +08:00
parent e73e2739c1
commit f0af36b59e
43 changed files with 62 additions and 62 deletions

View File

@@ -19,7 +19,7 @@ type Notifier interface {
// 出参:
// - res发送结果。
// - err: 错误。
Notify(ctx context.Context, subject string, message string) (res *NotifyResult, err error)
Notify(ctx context.Context, subject string, message string) (_res *NotifyResult, _err error)
}
// 表示通知发送结果的数据结构。

View File

@@ -49,7 +49,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
const defaultServerURL = "https://api.day.app/"
serverUrl := defaultServerURL
if n.config.ServerUrl != "" {

View File

@@ -45,7 +45,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
webhookUrl, err := url.Parse(n.config.WebhookUrl)
if err != nil {
return nil, fmt.Errorf("dingtalk api error: invalid webhook url: %w", err)

View File

@@ -48,7 +48,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
// REF: https://discord.com/developers/docs/resources/message#create-message
req := n.httpClient.R().
SetContext(ctx).

View File

@@ -57,7 +57,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
var smtpAuth smtp.Auth
if n.config.Username != "" || n.config.Password != "" {
smtpAuth = smtp.PlainAuth("", n.config.Username, n.config.Password, n.config.SmtpHost)
@@ -76,10 +76,11 @@ func (n *NotifierProvider) Notify(ctx context.Context, subject string, message s
var yak *mailyak.MailYak
if n.config.SmtpTls {
yak, err = mailyak.NewWithTLS(smtpAddr, smtpAuth, newTlsConfig())
yakWithTls, err := mailyak.NewWithTLS(smtpAddr, smtpAuth, newTlsConfig())
if err != nil {
return nil, err
}
yak = yakWithTls
} else {
yak = mailyak.New(smtpAddr, smtpAuth)
}
@@ -89,8 +90,7 @@ func (n *NotifierProvider) Notify(ctx context.Context, subject string, message s
yak.Subject(subject)
yak.Plain().Set(message)
err = yak.Send()
if err != nil {
if err := yak.Send(); err != nil {
return nil, err
}

View File

@@ -51,7 +51,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
serverUrl := strings.TrimRight(n.config.ServerUrl, "/")
// REF: https://gotify.net/api-docs#/message/createMessage

View File

@@ -42,7 +42,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
bot := lark.NewNotificationBot(n.config.WebhookUrl)
content := lark.NewPostBuilder().
Title(subject).

View File

@@ -53,7 +53,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
serverUrl := strings.TrimRight(n.config.ServerUrl, "/")
// REF: https://developers.mattermost.com/api-documentation/#/operations/Login

View File

@@ -48,7 +48,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
// REF: https://pushover.net/api
req := n.httpClient.R().
SetContext(ctx).

View File

@@ -47,7 +47,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
// REF: https://pushplus.plus/doc/guide/api.html#%E4%B8%80%E3%80%81%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3
req := n.httpClient.R().
SetContext(ctx).

View File

@@ -46,7 +46,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
// REF: https://sct.ftqq.com/
req := n.httpClient.R().
SetContext(ctx).

View File

@@ -48,7 +48,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
// REF: https://docs.slack.dev/messaging/sending-and-scheduling-messages#publishing
req := n.httpClient.R().
SetContext(ctx).

View File

@@ -48,7 +48,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
// REF: https://core.telegram.org/bots/api#sendmessage
req := n.httpClient.R().
SetContext(ctx).

View File

@@ -67,7 +67,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
// 处理 Webhook URL
webhookUrl, err := url.Parse(n.config.WebhookUrl)
if err != nil {

View File

@@ -46,7 +46,7 @@ func (n *NotifierProvider) WithLogger(logger *slog.Logger) notifier.Notifier {
return n
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
// REF: https://developer.work.weixin.qq.com/document/path/91770
req := n.httpClient.R().
SetContext(ctx).