6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-25 16:28:20 +00:00
prologic-saltyim/sendmsg.go

21 lines
495 B
Go

package saltyim
import (
"bytes"
"net/http"
log "github.com/sirupsen/logrus"
)
// Send sends the encrypted message `msg` to the Endpoint `endpoint` using a
// `POST` request and returns nil on success or an error on failure.
func Send(endpoint, msg string) error {
res, err := Request(http.MethodPost, endpoint, nil, bytes.NewBufferString(msg))
if err != nil {
log.WithError(err).Errorf("error publishing message to %s", endpoint)
return err
}
defer res.Body.Close()
return nil
}