You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
614 B
34 lines
614 B
package message
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"sendmsg/common"
|
|
"sendmsg/model"
|
|
)
|
|
|
|
type Bark struct {
|
|
url string
|
|
key string
|
|
}
|
|
|
|
func (b *Bark) Send(body Body) {
|
|
common.Log.Printf("[bark] sending message...")
|
|
var reqBody = model.BarkRequest{
|
|
DeviceKey: b.key,
|
|
Title: body.Title,
|
|
Body: body.Content,
|
|
}
|
|
req, _ := json.Marshal(reqBody)
|
|
resp, err := http.Post(b.url,
|
|
"application/json; charset=utf-8",
|
|
bytes.NewReader(req))
|
|
if err != nil {
|
|
common.Log.Fatalf("[bark] http post failed: %v\n", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
common.Log.Printf("[bark] Send successful")
|
|
}
|