Direct openai client, clean up deps and errors

This commit is contained in:
Ian Gulliver
2024-11-26 14:37:24 -06:00
parent c40777b689
commit 0b6e729706
5 changed files with 113 additions and 47 deletions

View File

@@ -45,24 +45,26 @@ func (pd *pdClient) sendAlert(msg string) error {
})
if err != nil {
return fmt.Errorf("Encode PD alert: %s", err)
return err
}
req, err := http.NewRequest("POST", "https://events.pagerduty.com/v2/enqueue", buf)
if err != nil {
return fmt.Errorf("Create HTTP request: %s", err)
return err
}
req.Header.Set("Content-Type", "application/json")
resp, err := pd.c.Do(req)
if err != nil {
return fmt.Errorf("Call PagerDuty: %s", err)
return err
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode != 202 {
return fmt.Errorf("PagerDuty error: %s", string(body))
return fmt.Errorf("%s", string(body))
}
return nil