-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithubStatus.go
More file actions
44 lines (35 loc) · 925 Bytes
/
githubStatus.go
File metadata and controls
44 lines (35 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
const GithubStatusSummaryUrl = "https://www.githubstatus.com/api/v2/summary.json"
type Response struct {
Components []Component `json:"components"`
}
type Component struct {
Name string `json:"name"`
Status string `json:"status"`
}
func (c Component) IsOperational() bool {
return c.Status == "operational"
}
func GetGithubStatusComponents() ([]Component, error) {
resp, err := http.Get(GithubStatusSummaryUrl)
if err != nil {
return nil, fmt.Errorf("failed to get github status: %w", err)
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read github status response: %w", err)
}
var result Response
err = json.Unmarshal(data, &result)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal github status response: %w", err)
}
return result.Components, nil
}