diff options
| author | Christine Dodrill <me@christine.website> | 2018-10-04 18:37:12 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2018-10-04 18:37:12 -0700 |
| commit | 1ea65cb9255af99adcf3cd8f55e6e2f336408a73 (patch) | |
| tree | 4ecf120976ef7553b4c578fa43b073592fdd8926 /web | |
| parent | 7103fa3380d0038b4e1a452ef6aa8f3c3a9298ca (diff) | |
| download | x-1ea65cb9255af99adcf3cd8f55e6e2f336408a73.tar.xz x-1ea65cb9255af99adcf3cd8f55e6e2f336408a73.zip | |
tools/ghstat: move github status library to a new-style Go library
Diffstat (limited to 'web')
| -rw-r--r-- | web/ghstat/ghstat.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/web/ghstat/ghstat.go b/web/ghstat/ghstat.go new file mode 100644 index 0000000..8d94214 --- /dev/null +++ b/web/ghstat/ghstat.go @@ -0,0 +1,48 @@ +// 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 +} |
