-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub_status.go
More file actions
75 lines (65 loc) · 1.98 KB
/
Copy pathgithub_status.go
File metadata and controls
75 lines (65 loc) · 1.98 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
// https://tutorialedge.net/golang/consuming-restful-api-with-go/
// https://mholt.github.io/json-to-go/
import (
"encoding/json"
"fmt"
"io"
"net/http"
"github.com/fatih/color"
)
type summary struct {
Components []struct {
CreatedAt string `json:"created_at"`
Description string `json:"description"`
Group bool `json:"group"`
GroupID interface{} `json:"group_id"`
ID string `json:"id"`
Name string `json:"name"`
OnlyShowIfDegraded bool `json:"only_show_if_degraded"`
PageID string `json:"page_id"`
Position int64 `json:"position"`
Showcase bool `json:"showcase"`
Status string `json:"status"`
UpdatedAt string `json:"updated_at"`
} `json:"components"`
Incidents []interface{} `json:"incidents"`
Page struct {
ID string `json:"id"`
Name string `json:"name"`
TimeZone string `json:"time_zone"`
UpdatedAt string `json:"updated_at"`
URL string `json:"url"`
} `json:"page"`
ScheduledMaintenances []interface{} `json:"scheduled_maintenances"`
Status struct {
Description string `json:"description"`
Indicator string `json:"indicator"`
} `json:"status"`
}
func main() {
response, err := http.Get("https://kctbh9vrtdwd.statuspage.io/api/v2/summary.json")
checkErr(err)
responseData, err := io.ReadAll(response.Body)
checkErr(err)
var responseObject summary
err = json.Unmarshal(responseData, &responseObject)
checkErr(err)
for _, component := range responseObject.Components {
fmt.Printf("%-60s", component.Name)
if component.Status == "operational" {
color.Set(color.FgGreen)
} else if component.Status == "major_outage" {
color.Set(color.FgRed)
} else {
color.Set(color.FgYellow)
}
fmt.Printf("%s\n", component.Status)
color.Unset()
}
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}