From 312b6810de840fb33fe8005ab8d9c50e14913fde Mon Sep 17 00:00:00 2001 From: zc Date: Sun, 17 Apr 2022 19:10:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89ba?= =?UTF-8?q?rk=20server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.yaml | 3 ++- pkg/notice/bark.go | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 8190a92..768fbe5 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,5 +1,6 @@ bark: - key: "" # Bark 通知推送的 Key + server: "https://api.day.app" # 自定义 Bark Server 地址, 不填默认为 https://api.day.app + key: "" # Bark 通知推送的 Key push_plus: token: "" # Push Plus 通知推送的 Token regular: diff --git a/pkg/notice/bark.go b/pkg/notice/bark.go index 1f1b67d..9c1e6ae 100644 --- a/pkg/notice/bark.go +++ b/pkg/notice/bark.go @@ -20,23 +20,25 @@ import ( "fmt" "io/ioutil" "net/http" + "path" ) const barkURL = "https://api.day.app/push" type BarkConfig struct { - Key string `json:"key"` + Server string `json:"server"` + Key string `json:"key"` } func NewBark(cfg *BarkConfig) Engine { if cfg.Key == "" { return nil } - return &bark{key: cfg.Key} + return &bark{cfg: cfg} } type bark struct { - key string + cfg *BarkConfig } func (b *bark) Name() string { @@ -45,7 +47,7 @@ func (b *bark) Name() string { func (b *bark) Send(title, body string) error { data := &barkData{ - DeviceKey: b.key, + DeviceKey: b.cfg.Key, Title: title, Body: body, Sound: "alarm.caf", @@ -55,7 +57,11 @@ func (b *bark) Send(title, body string) error { return err } - resp, err := http.Post(barkURL, "application/json; charset=utf-8", bytes.NewReader(bs)) + uri := barkURL + if b.cfg.Server != "" { + uri = path.Join(b.cfg.Server, "push") + } + resp, err := http.Post(uri, "application/json; charset=utf-8", bytes.NewReader(bs)) if err != nil { return err }