incus-sentinel/http_notifier/main.go

28 lines
550 B
Go
Raw Normal View History

2025-01-05 09:34:06 +00:00
package http_notifier
import (
"fmt"
"net/http"
"slices"
)
type HTTPNotifier struct{}
func NewNotifier() *HTTPNotifier {
return &HTTPNotifier{}
}
func (n *HTTPNotifier) Notify(url string) error {
resp, err := http.Get(url)
if err != nil {
return fmt.Errorf("Failed to call URL %s: %s", url, err.Error())
}
defer resp.Body.Close()
if !slices.Contains([]int{http.StatusOK, http.StatusCreated, http.StatusNoContent}, resp.StatusCode) {
return fmt.Errorf("Unexpected status code %d from URL %s", resp.StatusCode, url)
}
return nil
}