fix: streamline Notify function with switch-case for notification methods

This commit is contained in:
Laisky.Cai 2025-03-09 12:52:08 +00:00
parent 388f0ef6aa
commit 3e432c77bd

View File

@ -1,6 +1,8 @@
package message
import (
"fmt"
"github.com/pkg/errors"
"github.com/songquanpeng/one-api/common/config"
)
@ -12,8 +14,8 @@ const (
)
func Notify(by string, title string, description string, content string) error {
if by == ByAll {
switch by {
case ByAll:
var errMsgs []string
if err := SendEmail(title, config.RootUserEmail, content); err != nil {
errMsgs = append(errMsgs, fmt.Sprintf("failed to send email: %v", err))
@ -26,13 +28,11 @@ func Notify(by string, title string, description string, content string) error {
return fmt.Errorf("multiple errors occurred: %v", errMsgs)
}
return nil
}
if by == ByEmail {
case ByEmail:
return SendEmail(title, config.RootUserEmail, content)
}
if by == ByMessagePusher {
case ByMessagePusher:
return SendMessage(title, description, content)
default:
return errors.Errorf("unknown notify method: %s", by)
}
return errors.Errorf("unknown notify method: %s", by)
}