scron/gotify.go
kekskurse 01e283f96b
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
feat: gotify notification
2025-07-31 18:43:03 +02:00

40 lines
953 B
Go

package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type Message struct {
Title string `json:"title,omitempty"`
Message string `json:"message"`
Priority int `json:"priority,omitempty"`
Extras map[string]interface{} `json:"extras,omitempty"`
}
func SendGotifyNotification(url string, msg Message) error {
bodyBytes, err := json.Marshal(msg)
if err != nil {
return fmt.Errorf("failed to encode payload: %w", err)
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(bodyBytes))
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("HTTP request error: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected status: %s", resp.Status)
}
return nil
}