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
609 B

2 years ago
package message
import (
"bytes"
"encoding/json"
log "github.com/sirupsen/logrus"
2 years ago
"net/http"
"sendmsg/model"
)
type Bark struct {
url string
key string
}
func (b *Bark) Send(body Body) {
log.Printf("[bark] sending message...")
2 years ago
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 {
log.Fatalf("[bark] http post failed: %v\n", err)
2 years ago
}
defer resp.Body.Close()
log.Printf("[bark] Send successful")
2 years ago
}