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