This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
status.go
75 lines (64 loc) · 1.63 KB
/
status.go
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
import (
"encoding/json"
"fmt"
"net/http"
"os"
"time"
)
var cmdStatus = &Command{
Run: runStatus,
Usage: "status",
Category: "misc",
Short: "display heroku platform status" + extra,
Long: `
Displays the current status of the Heroku platform.
Examples:
$ hk status
Production: No known issues at this time.
Development: No known issues at this time.
`,
}
type statusResponse struct {
Status struct {
Production string
Development string
} `json:"status"`
Issues []statusIssue
}
type statusIssue struct {
Resolved bool `json:"resolved"`
StatusDev string `json:"status_dev"`
StatusProd string `json:"status_prod"`
Title string `json:"title"`
Upcoming bool `json:"upcoming"`
Href string `json:"href"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func runStatus(cmd *Command, args []string) {
if len(args) != 0 {
cmd.PrintUsage()
os.Exit(2)
}
herokuStatusHost := "status.heroku.com"
if e := os.Getenv("HEROKU_STATUS_HOST"); e != "" {
herokuStatusHost = e
}
res, err := http.Get("https://" + herokuStatusHost + "/api/v3/current-status.json")
must(err)
if res.StatusCode/100 != 2 { // 200, 201, 202, etc
printFatal("unexpected HTTP status: %d", res.StatusCode)
}
var sr statusResponse
err = json.NewDecoder(res.Body).Decode(&sr)
must(err)
fmt.Println("Production: ", statusValueFromColor(sr.Status.Production))
fmt.Println("Development: ", statusValueFromColor(sr.Status.Development))
}
func statusValueFromColor(color string) string {
if color == "green" {
return "No known issues at this time."
}
return color
}