diff options
| author | Christine Dodrill <me@christine.website> | 2019-01-29 03:33:27 -0800 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2019-01-29 03:33:27 -0800 |
| commit | 10f1a7ca7bec98cc65e6c65f7126d1e303b98ef6 (patch) | |
| tree | fac969dc194f2e6229653a4dd72fa79e8e330fe1 | |
| parent | b395841f422fd9c6e50b4be979da0f308f9499a9 (diff) | |
| download | x-10f1a7ca7bec98cc65e6c65f7126d1e303b98ef6.tar.xz x-10f1a7ca7bec98cc65e6c65f7126d1e303b98ef6.zip | |
GitHub Status API is deprecated :(
| -rw-r--r-- | tools/ghstat/.gitignore | 1 | ||||
| -rw-r--r-- | tools/ghstat/README.md | 9 | ||||
| -rw-r--r-- | tools/ghstat/doc.go | 10 | ||||
| -rw-r--r-- | tools/ghstat/main.go | 65 | ||||
| -rw-r--r-- | web/ghstat/ghstat.go | 48 |
5 files changed, 0 insertions, 133 deletions
diff --git a/tools/ghstat/.gitignore b/tools/ghstat/.gitignore deleted file mode 100644 index 7e9712b..0000000 --- a/tools/ghstat/.gitignore +++ /dev/null @@ -1 +0,0 @@ -ghstat diff --git a/tools/ghstat/README.md b/tools/ghstat/README.md deleted file mode 100644 index 0ff7b52..0000000 --- a/tools/ghstat/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# ghstat --- -Command ghstat shows the status of GitHub via their status API. - - Usage of ./ghstat: - -message=false: show last message? - -This follows https://status.github.com/api for all but the list of all recent -status messages. diff --git a/tools/ghstat/doc.go b/tools/ghstat/doc.go deleted file mode 100644 index 634c3bc..0000000 --- a/tools/ghstat/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -/* -Command ghstat shows the status of GitHub via their status API. - - Usage of ./ghstat: - -message=false: show last message? - -This follows https://status.github.com/api for all but the list of all -recent status messages. -*/ -package main diff --git a/tools/ghstat/main.go b/tools/ghstat/main.go deleted file mode 100644 index 1cf0c6e..0000000 --- a/tools/ghstat/main.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "encoding/json" - "flag" - "fmt" - "log" - "net/http" - "os" - - "github.com/Xe/x/internal" - "github.com/Xe/x/web/ghstat" -) - -var ( - messageFlag = flag.Bool("message", false, "show last message?") - - // TODO: implement - //shellFlag = flag.Bool("s", false, "show as shell prompt artifact") -) - -func main() { - internal.HandleStartup() - - if *messageFlag { - req := ghstat.LastMessage() - resp, err := http.DefaultClient.Do(req) - if err != nil { - log.Fatal(err) - } - - var m ghstat.Message - defer resp.Body.Close() - err = json.NewDecoder(resp.Body).Decode(&m) - if err != nil { - log.Fatal(err) - } - - fmt.Printf("Last message:\n") - fmt.Printf("Status: %s\n", m.Status) - fmt.Printf("Message: %s\n", m.Body) - fmt.Printf("Time: %s\n", m.CreatedOn) - - return - } - - req := ghstat.LastStatus() - resp, err := http.DefaultClient.Do(req) - if err != nil { - log.Fatal(err) - } - - var s ghstat.Status - defer resp.Body.Close() - err = json.NewDecoder(resp.Body).Decode(&s) - if err != nil { - log.Fatal(err) - } - - fmt.Printf("Status: %s (%s)\n", s.Status, s.LastUpdated) - - if s.Status != "good" { - os.Exit(1) - } -} diff --git a/web/ghstat/ghstat.go b/web/ghstat/ghstat.go deleted file mode 100644 index 8d94214..0000000 --- a/web/ghstat/ghstat.go +++ /dev/null @@ -1,48 +0,0 @@ -// Package ghstat is a set of wrappers for the GitHub Status API. -package ghstat - -import "net/http" - -// Status is the human-readable status for GitHub's platform. -type Status struct { - Status string `json:"status"` - LastUpdated string `json:"last_updated"` -} - -// GitHub status API constants. -const ( - GHStatusAPIRoot = `https://status.github.com/api/` - StatusPath = `status.json` - MessagePath = `last-message.json` -) - -// LastStatus returns a request to the most recent status for GitHub's platform. -func LastStatus() *http.Request { - req, err := http.NewRequest(http.MethodGet, GHStatusAPIRoot+StatusPath, nil) - if err != nil { - panic(err) - } - - req.Header.Set("Accept", "application/json") - - return req -} - -// Message is an individiual human-readable message associated with a status update. -type Message struct { - Status string `json:"status"` - Body string `json:"body"` - CreatedOn string `json:"created_on"` -} - -// LastMessage returns a request to the most recent message for GitHub's platform. -func LastMessage() *http.Request { - req, err := http.NewRequest(http.MethodGet, GHStatusAPIRoot+StatusPath, nil) - if err != nil { - panic(err) - } - - req.Header.Set("Accept", "application/json") - - return req -} |
