diff options
| author | Christine Dodrill <me@christine.website> | 2017-03-29 11:14:59 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2017-03-29 11:14:59 -0700 |
| commit | e7824cb2609cc32d4229c9a7bc0de7b7153d36ef (patch) | |
| tree | e14b68f2ea178ca1d96fa87d5cb1686e71a41695 /ghstat | |
| parent | 77416787c09e1a45f487e5f932a5c688469c730d (diff) | |
| download | x-e7824cb2609cc32d4229c9a7bc0de7b7153d36ef.tar.xz x-e7824cb2609cc32d4229c9a7bc0de7b7153d36ef.zip | |
reorganization
Diffstat (limited to 'ghstat')
| -rw-r--r-- | ghstat/.gitignore | 1 | ||||
| -rw-r--r-- | ghstat/README.md | 9 | ||||
| -rw-r--r-- | ghstat/doc.go | 10 | ||||
| -rw-r--r-- | ghstat/main.go | 54 | ||||
| -rw-r--r-- | ghstat/types.go | 60 |
5 files changed, 0 insertions, 134 deletions
diff --git a/ghstat/.gitignore b/ghstat/.gitignore deleted file mode 100644 index 7e9712b..0000000 --- a/ghstat/.gitignore +++ /dev/null @@ -1 +0,0 @@ -ghstat diff --git a/ghstat/README.md b/ghstat/README.md deleted file mode 100644 index 0ff7b52..0000000 --- a/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/ghstat/doc.go b/ghstat/doc.go deleted file mode 100644 index 634c3bc..0000000 --- a/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/ghstat/main.go b/ghstat/main.go deleted file mode 100644 index f86861e..0000000 --- a/ghstat/main.go +++ /dev/null @@ -1,54 +0,0 @@ -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/ghstat/types.go b/ghstat/types.go deleted file mode 100644 index ef824bd..0000000 --- a/ghstat/types.go +++ /dev/null @@ -1,60 +0,0 @@ -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 -} |
