diff --git a/common/message/main.go b/common/message/main.go index 20bab35e..2aa4657d 100644 --- a/common/message/main.go +++ b/common/message/main.go @@ -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) }