-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completely rework the system to pull statues
The CLI command now provides one status at a time, based on the name provided. A future PR will reinstate multiple statues in some form or fashion. The status handling itself has been moved into a module Go package. This will make it easier to add new status pages and status page providers in the future.
- Loading branch information
1 parent
e98edc4
commit 6d8280c
Showing
13 changed files
with
334 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package statuses | ||
|
||
/* | ||
* Register the CircleCI status page. | ||
*/ | ||
func init() { | ||
RegisterStatusPageIOPage("circleci", "https://status.circleci.com/api/v2/status.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package statuses | ||
|
||
/* | ||
* Register the CircleCI status page. | ||
*/ | ||
func init() { | ||
RegisterStatusPageIOPage("cloudflare", "https://www.cloudflarestatus.com/api/v2/status.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package statuses | ||
|
||
/* | ||
* Register the CircleCI status page. | ||
*/ | ||
func init() { | ||
RegisterStatusPageIOPage("digitalocean", "https://status.digitalocean.com/api/v2/status.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package statuses | ||
|
||
/* | ||
* Register the Docker (company) status page. | ||
*/ | ||
func init() { | ||
RegisterStatusIOPage("docker", "https://www.dockerstatus.com/1.0/status/533c6539221ae15e3f000031") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package statuses | ||
|
||
import "fmt" | ||
|
||
/* | ||
* NameTakenError occurs when a status page is registered with a name that is | ||
* already registered. | ||
*/ | ||
type NameTakenError struct { | ||
Name string | ||
} | ||
|
||
/* | ||
* Error returns the string representation of NameTakenError. | ||
*/ | ||
func (e *NameTakenError) Error() string { | ||
return fmt.Sprintf("Failed to register the name %s. It has already been taken.", e.Name) | ||
} | ||
|
||
/* | ||
* newNameTakenError creates a new NameTakenError. | ||
*/ | ||
func newNameTakenError(name string) *NameTakenError { | ||
return &NameTakenError{Name: name} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package statuses | ||
|
||
/* | ||
* Register the CircleCI status page. | ||
*/ | ||
func init() { | ||
RegisterStatusPageIOPage("github", "https://www.githubstatus.com/api/v2/status.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package statuses | ||
|
||
/* | ||
* Register the Docker (company) status page. | ||
*/ | ||
func init() { | ||
RegisterStatusIOPage("gitlab", "https://status.gitlab.com/1.0/status/5b36dc6502d06804c08349f7") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package statuses | ||
|
||
/* | ||
* Register the CircleCI status page. | ||
*/ | ||
func init() { | ||
RegisterStatusPageIOPage("linode", "https://status.linode.com/api/v2/status.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package statuses | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
// This is how the package keeps track of all the status pages that it knows | ||
// about. | ||
var registeredPages map[string]StatusPage = map[string]StatusPage{} | ||
|
||
/* | ||
* GetPageURL returns a status page's API URL. | ||
*/ | ||
func Page(name string) (StatusPage, error) { | ||
|
||
sp, ok := registeredPages[name] | ||
if !ok { | ||
return nil, fmt.Errorf("Not a registered page.") | ||
} | ||
|
||
return sp, nil | ||
} | ||
|
||
/* | ||
* registerPage adds a new status page to the list for a specific company / | ||
* provider. | ||
* | ||
* name - should be a unique slug | ||
*/ | ||
func registerPage(provider StatusPage) error { | ||
|
||
name := provider.Name() | ||
|
||
// If the name has already been used. | ||
if _, ok := registeredPages[name]; ok { | ||
return newNameTakenError(name) | ||
} | ||
|
||
// If the URL provided is no good. | ||
if _, err := url.Parse(provider.URL()); err != nil { | ||
return err | ||
} | ||
|
||
registeredPages[name] = provider | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package statuses | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
/* | ||
* This file defines the structs and other components needed to represent a | ||
* status page hosted by Status.io. | ||
*/ | ||
|
||
/* | ||
* statusIOStatus represents the individual component status as well as most | ||
* of the overall status. | ||
*/ | ||
type StatusIOStatus struct { | ||
Status string `json:"status"` | ||
StatusCode int `json:"status_code"` | ||
} | ||
|
||
/* | ||
* statusIOReponse represents the JSON response from the StatusPage.io API. | ||
*/ | ||
type statusIOResponse struct { | ||
Result struct { | ||
StatusOverall struct { | ||
Updated time.Time `json:"updated"` | ||
*StatusIOStatus | ||
} `json:"status_overall"` | ||
} `json:"result"` | ||
} | ||
|
||
/* | ||
* statusIOProvider represents the way to connect to the API and retrieve a | ||
* response. | ||
*/ | ||
type statusIOProvider struct { | ||
name string | ||
apiURL string | ||
data *statusIOResponse | ||
} | ||
|
||
/* | ||
* Fetch pulls in a response from the API. | ||
*/ | ||
func (p *statusIOProvider) Fetch(c *http.Client) error { | ||
|
||
return fetchJSON(c, p.apiURL, &p.data) | ||
} | ||
|
||
func (p *statusIOProvider) Name() string { | ||
return p.name | ||
} | ||
|
||
func (p *statusIOProvider) URL() string { | ||
return p.apiURL | ||
} | ||
|
||
func (p *statusIOProvider) Status() (string, error) { | ||
|
||
if p.data == nil { | ||
return "", fmt.Errorf("Data hasn't been retrieved.") | ||
} | ||
|
||
return p.data.Result.StatusOverall.Status, nil | ||
} | ||
|
||
/* | ||
* RegisterStatusIOPage creates a new provider. | ||
*/ | ||
func RegisterStatusIOPage(name, apiURL string) error { | ||
return registerPage(&statusIOProvider{name: name, apiURL: apiURL}) | ||
} |
Oops, something went wrong.