mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-19 10:06: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
|
package message
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/songquanpeng/one-api/common/config"
|
"github.com/songquanpeng/one-api/common/config"
|
||||||
)
|
)
|
||||||
@ -12,8 +14,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Notify(by string, title string, description string, content string) error {
|
func Notify(by string, title string, description string, content string) error {
|
||||||
|
switch by {
|
||||||
if by == ByAll {
|
case ByAll:
|
||||||
var errMsgs []string
|
var errMsgs []string
|
||||||
if err := SendEmail(title, config.RootUserEmail, content); err != nil {
|
if err := SendEmail(title, config.RootUserEmail, content); err != nil {
|
||||||
errMsgs = append(errMsgs, fmt.Sprintf("failed to send email: %v", err))
|
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 fmt.Errorf("multiple errors occurred: %v", errMsgs)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
case ByEmail:
|
||||||
|
|
||||||
if by == ByEmail {
|
|
||||||
return SendEmail(title, config.RootUserEmail, content)
|
return SendEmail(title, config.RootUserEmail, content)
|
||||||
}
|
case ByMessagePusher:
|
||||||
if by == ByMessagePusher {
|
|
||||||
return SendMessage(title, description, content)
|
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