From 1ea65cb9255af99adcf3cd8f55e6e2f336408a73 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Thu, 4 Oct 2018 18:37:12 -0700 Subject: tools/ghstat: move github status library to a new-style Go library --- web/ghstat/ghstat.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 web/ghstat/ghstat.go (limited to 'web') 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 +} -- cgit v1.2.3