Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/cli. OpenStatus CLI www.openstatus.dev
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950package monitors
import ( "bytes" "encoding/json" "fmt" "io" "net/http"
"github.com/openstatusHQ/cli/internal/config")
func UpdateMonitor(httpClient *http.Client, apiKey string, id int, monitor config.Monitor) (Monitor, error) {
url := fmt.Sprintf("%s/monitor/%s/%d", APIBaseURL, monitor.Kind, id)
payloadBuf := new(bytes.Buffer) json.NewEncoder(payloadBuf).Encode(monitor) req, err := http.NewRequest(http.MethodPut, url, payloadBuf) if err != nil { return Monitor{}, fmt.Errorf("failed to create request: %w", err) }
req.Header.Add("x-openstatus-key", apiKey) req.Header.Add("Content-Type", "application/json")
res, err := httpClient.Do(req) if err != nil { return Monitor{}, err }
if res.StatusCode != http.StatusOK { return Monitor{}, fmt.Errorf("Failed to Update monitor") }
defer res.Body.Close() body, err := io.ReadAll(res.Body) if err != nil { return Monitor{}, fmt.Errorf("failed to read response body: %w", err) }
var monitors Monitor err = json.Unmarshal(body, &monitors) if err != nil { return Monitor{}, err }
return monitors, nil}