33 lines
719 B
Go
33 lines
719 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"encoding/json"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type DiscordWebhookPayload struct {
|
||
|
Content string `json:"content"`
|
||
|
}
|
||
|
|
||
|
func sendDiscordNotification(content string) {
|
||
|
payload := DiscordWebhookPayload{Content: content}
|
||
|
payloadBytes, err := json.Marshal(payload)
|
||
|
if err != nil {
|
||
|
log.Printf("Error marshalling Discord webhook payload: %v", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
resp, err := http.Post(discordWebhookURL, "application/json", bytes.NewBuffer(payloadBytes))
|
||
|
if err != nil {
|
||
|
log.Printf("Error sending Discord webhook: %v", err)
|
||
|
return
|
||
|
}
|
||
|
defer resp.Body.Close()
|
||
|
|
||
|
if resp.StatusCode != http.StatusNoContent {
|
||
|
log.Printf("Unexpected status code from Discord webhook: %d", resp.StatusCode)
|
||
|
}
|
||
|
}
|