package message import ( "bytes" "encoding/json" "log" "message-demo/global" "net/http" ) type Bark struct { url string key string } var b = Bark{} func initBark() { //b.url = "https://bark.zggsong.cn/push/" //b.key = "CpYMsRyciG9hrktVXSAeW3" //mac //b.key = "wHfht3s7R3wTEUB2FmSHM8" //iphone b.url = global.GLO_CONF.BarkUrl b.key = global.GLO_CONF.BarkKey Register("bark", b) } func (m Bark) Send(message MessageBody) { log.Println("[bark] Sending by bark...") var reqBody = Request{ DeviceKey: b.key, Title: message.Title, Body: message.Content, // Url: "https:////github.com/zggsong", } req, _ := json.Marshal(reqBody) resp, err := http.Post(m.url, "application/json; charset=utf-8", bytes.NewReader(req)) if err != nil { log.Fatalf("[bark] http post failed: %v\n", err) } defer resp.Body.Close() log.Printf("[bark] Send successful") } type Request struct { Body string `json:"body"` DeviceKey string `json:"device_key"` Title string `json:"title"` Badge int `json:"badge"` Category string `json:"category"` Sound string `json:"sound"` Icon string `json:"icon"` Group string `json:"group"` Url string `json:"url"` } type Response struct { Code int `json:"code"` Message string `json:"message"` Timestamp int `json:"timestamp"` }