feat: add bark push notification

This commit is contained in:
Simon Ding
2024-07-29 18:06:32 +08:00
parent eed72c5eb9
commit e08c126af2
4 changed files with 153 additions and 19 deletions

View File

@@ -3,6 +3,7 @@ package notifier
import (
"encoding/json"
"github.com/nikoksr/notify/service/bark"
"github.com/nikoksr/notify/service/dingding"
po "github.com/nikoksr/notify/service/pushover"
"github.com/nikoksr/notify/service/telegram"
@@ -68,3 +69,22 @@ func NewTelegramClient(s string) (NotificationClient, error) {
svc.AddReceivers(cfg.ChatID)
return &Notifier{service: svc}, nil
}
type BarkConfig struct {
DeviceKey string `json:"device_key"`
URL string `json:"url"`
}
func NewbarkClient(s string) (NotificationClient, error) {
var cfg BarkConfig
if err := json.Unmarshal([]byte(s), &cfg); err != nil {
return nil, errors.Wrap(err, "json")
}
url := cfg.URL
if url == "" {
url = bark.DefaultServerURL
}
b := bark.NewWithServers(cfg.DeviceKey, url)
return &Notifier{service: b}, nil
}