mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-19 01:56:37 +08:00
fix: streamline Notify function with switch-case for notification methods
This commit is contained in:
parent
388f0ef6aa
commit
3e432c77bd
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user