SOME OF THE PROJECTS ARE MOVED IN THEIR SEPARATE REPOSITORIES
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.

37 lines
724 B

package discordhooks
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type Webhook struct {
WebhookUrl string
}
const contentTypeJson string = "application/json"
type Message struct {
Message string `json:"content"`
Username string `json:"username"`
AvatarURL string `json:"avatar_url"`
}
// Post Message struct to given webhook
func Post(webhookUrl string, message Message) error {
json, err := json.Marshal(&message)
if err != nil {
return fmt.Errorf("could not marshal given JsonMessage: %s", err)
}
resp, err := http.Post(webhookUrl, contentTypeJson, bytes.NewBuffer(json))
if err != nil {
return fmt.Errorf("could not POST to given url: %s", err)
}
defer resp.Body.Close()
return nil
}