github.com/koron/hk@v0.0.0-20150303213137-b8aeaa3ab34c/status.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "net/http" 7 "os" 8 "time" 9 ) 10 11 var cmdStatus = &Command{ 12 Run: runStatus, 13 Usage: "status", 14 Category: "misc", 15 Short: "display heroku platform status" + extra, 16 Long: ` 17 Displays the current status of the Heroku platform. 18 19 Examples: 20 21 $ hk status 22 Production: No known issues at this time. 23 Development: No known issues at this time. 24 `, 25 } 26 27 type statusResponse struct { 28 Status struct { 29 Production string 30 Development string 31 } `json:"status"` 32 Issues []statusIssue 33 } 34 35 type statusIssue struct { 36 Resolved bool `json:"resolved"` 37 StatusDev string `json:"status_dev"` 38 StatusProd string `json:"status_prod"` 39 Title string `json:"title"` 40 Upcoming bool `json:"upcoming"` 41 Href string `json:"href"` 42 43 CreatedAt time.Time `json:"created_at"` 44 UpdatedAt time.Time `json:"updated_at"` 45 } 46 47 func runStatus(cmd *Command, args []string) { 48 if len(args) != 0 { 49 cmd.PrintUsage() 50 os.Exit(2) 51 } 52 herokuStatusHost := "status.heroku.com" 53 if e := os.Getenv("HEROKU_STATUS_HOST"); e != "" { 54 herokuStatusHost = e 55 } 56 res, err := http.Get("https://" + herokuStatusHost + "/api/v3/current-status.json") 57 must(err) 58 if res.StatusCode/100 != 2 { // 200, 201, 202, etc 59 printFatal("unexpected HTTP status: %d", res.StatusCode) 60 } 61 62 var sr statusResponse 63 err = json.NewDecoder(res.Body).Decode(&sr) 64 must(err) 65 66 fmt.Println("Production: ", statusValueFromColor(sr.Status.Production)) 67 fmt.Println("Development: ", statusValueFromColor(sr.Status.Development)) 68 } 69 70 func statusValueFromColor(color string) string { 71 if color == "green" { 72 return "No known issues at this time." 73 } 74 return color 75 }