32 lines
642 B
Go
32 lines
642 B
Go
package http_notifier
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"slices"
|
|
"time"
|
|
)
|
|
|
|
type HTTPNotifier struct{}
|
|
|
|
func NewNotifier() *HTTPNotifier {
|
|
return &HTTPNotifier{}
|
|
}
|
|
|
|
func (n *HTTPNotifier) Notify(url string) error {
|
|
client := &http.Client{
|
|
Timeout: 10 * time.Second, // Set timeout duration
|
|
}
|
|
|
|
resp, err := client.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
|
|
}
|