aboutsummaryrefslogtreecommitdiff
path: root/tools/ghstat
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2017-03-29 11:14:59 -0700
committerChristine Dodrill <me@christine.website>2017-03-29 11:14:59 -0700
commite7824cb2609cc32d4229c9a7bc0de7b7153d36ef (patch)
treee14b68f2ea178ca1d96fa87d5cb1686e71a41695 /tools/ghstat
parent77416787c09e1a45f487e5f932a5c688469c730d (diff)
downloadx-e7824cb2609cc32d4229c9a7bc0de7b7153d36ef.tar.xz
x-e7824cb2609cc32d4229c9a7bc0de7b7153d36ef.zip
reorganization
Diffstat (limited to 'tools/ghstat')
-rw-r--r--tools/ghstat/.gitignore1
-rw-r--r--tools/ghstat/README.md9
-rw-r--r--tools/ghstat/doc.go10
-rw-r--r--tools/ghstat/main.go54
-rw-r--r--tools/ghstat/types.go60
5 files changed, 134 insertions, 0 deletions
diff --git a/tools/ghstat/.gitignore b/tools/ghstat/.gitignore
new file mode 100644
index 0000000..7e9712b
--- /dev/null
+++ b/tools/ghstat/.gitignore
@@ -0,0 +1 @@
+ghstat
diff --git a/tools/ghstat/README.md b/tools/ghstat/README.md
new file mode 100644
index 0000000..0ff7b52
--- /dev/null
+++ b/tools/ghstat/README.md
@@ -0,0 +1,9 @@
+# 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
new file mode 100644
index 0000000..634c3bc
--- /dev/null
+++ b/tools/ghstat/doc.go
@@ -0,0 +1,10 @@
+/*
+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
new file mode 100644
index 0000000..f86861e
--- /dev/null
+++ b/tools/ghstat/main.go
@@ -0,0 +1,54 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "log"
+ "os"
+ "time"
+)
+
+var (
+ messageFlag = flag.Bool("message", false, "show last message?")
+
+ // TODO: implement
+ //shellFlag = flag.Bool("s", false, "show as shell prompt artifact")
+)
+
+func main() {
+ flag.Parse()
+
+ if *messageFlag {
+ m, err := getMessage()
+ 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)
+
+ t, err := time.Parse(time.RFC3339, m.CreatedOn)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Printf("Time: %s\n", t.Format(time.ANSIC))
+ } else {
+ s, err := getStatus()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ t, err := time.Parse(time.RFC3339, s.LastUpdated)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Printf("Status: %s (%s)\n", s.Status, t.Format(time.ANSIC))
+
+ if s.Status != "good" {
+ os.Exit(1)
+ }
+ }
+}
diff --git a/tools/ghstat/types.go b/tools/ghstat/types.go
new file mode 100644
index 0000000..ef824bd
--- /dev/null
+++ b/tools/ghstat/types.go
@@ -0,0 +1,60 @@
+package main
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "net/http"
+)
+
+type Status struct {
+ Status string `json:"status"`
+ LastUpdated string `json:"last_updated"`
+}
+
+type Message struct {
+ Status string `json:"status"`
+ Body string `json:"body"`
+ CreatedOn string `json:"created_on"`
+}
+
+func getMessage() (Message, error) {
+ m := Message{}
+
+ resp, err := http.Get("https://status.github.com/api/last-message.json")
+ if err != nil {
+ return Message{}, err
+ }
+ defer resp.Body.Close()
+ content, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return Message{}, err
+ }
+
+ err = json.Unmarshal(content, &m)
+ if err != nil {
+ return Message{}, err
+ }
+
+ return m, nil
+}
+
+func getStatus() (Status, error) {
+ s := Status{}
+
+ resp, err := http.Get("https://status.github.com/api/status.json")
+ if err != nil {
+ return Status{}, err
+ }
+ defer resp.Body.Close()
+ content, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return Status{}, err
+ }
+
+ err = json.Unmarshal(content, &s)
+ if err != nil {
+ return Status{}, err
+ }
+
+ return s, nil
+}