mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 11:39:46 +08:00
feat: support push notification clients
This commit is contained in:
36
pkg/notifier/doc.go
Normal file
36
pkg/notifier/doc.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package notifier
|
||||
|
||||
import (
|
||||
"context"
|
||||
"polaris/pkg/utils"
|
||||
|
||||
"github.com/nikoksr/notify"
|
||||
)
|
||||
|
||||
type HandlerFunc func(string) (NotificationClient, error)
|
||||
|
||||
type NotificationClient interface {
|
||||
SendMsg(msg string) error
|
||||
}
|
||||
|
||||
type Notifier struct {
|
||||
service notify.Notifier
|
||||
}
|
||||
|
||||
func (s *Notifier) SendMsg(msg string) error {
|
||||
notifier := notify.New()
|
||||
notifier.UseServices(s.service)
|
||||
return notifier.Send(context.TODO(), "polaris", msg)
|
||||
}
|
||||
|
||||
var handler = utils.Map[string, HandlerFunc]{}
|
||||
|
||||
func init() {
|
||||
handler.Store("pushover", NewPushoverClient)
|
||||
handler.Store("dingtalk", NewDingTalkClient)
|
||||
handler.Store("telegram", NewTelegramClient)
|
||||
}
|
||||
|
||||
func Gethandler(name string) (HandlerFunc, bool) {
|
||||
return handler.Load(name)
|
||||
}
|
||||
Reference in New Issue
Block a user