Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.7 kB ยท 71 lines
Go
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172package workflows
import ( "bytes" "context" "encoding/json" "fmt" "net/http" "os")
func getBaseURL() string { if url := os.Getenv("WORKFLOWS_URL"); url != "" { return url } return "https://openstatus-workflows.fly.dev"}
type Payload struct { MonitorID string `json:"monitorId"` PrivateLocationID string `json:"privateLocationId"` Status string `json:"status"` Message string `json:"message,omitempty"` CronTimestamp int64 `json:"cronTimestamp"` Latency int64 `json:"latency,omitempty"` StatusCode int `json:"statusCode,omitempty"`}
type Client interface { Report(ctx context.Context, payload Payload) error}
type client struct { httpClient *http.Client cronSecret string baseURL string}
func NewClient(httpClient *http.Client, cronSecret string) Client { return client{ httpClient: httpClient, cronSecret: cronSecret, baseURL: getBaseURL(), }}
func (c client) Report(ctx context.Context, payload Payload) error { var body bytes.Buffer if err := json.NewEncoder(&body).Encode(payload); err != nil { return fmt.Errorf("unable to encode payload: %w", err) }
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/updateStatusPrivate", bytes.NewReader(body.Bytes())) if err != nil { return fmt.Errorf("unable to create request: %w", err) } req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Basic "+c.cronSecret)
resp, err := c.httpClient.Do(req) if err != nil { return fmt.Errorf("unable to send request: %w", err) } defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { return fmt.Errorf("unexpected status code: %d", resp.StatusCode) }
return nil}