File tree 1 file changed +63
-0
lines changed
1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ package statuses
2
+
3
+ import (
4
+ "fmt"
5
+ "net/http"
6
+ )
7
+
8
+ /*
9
+ * This file defines the structs and other components needed to represent a
10
+ * status page hosted by InstatusStatus.com.
11
+ */
12
+
13
+ type inStatusPageField struct {
14
+ Name string `json:"name"`
15
+ URL string `url:"url"`
16
+ Status string `url:"status"`
17
+ }
18
+
19
+ type inStatusResponse struct {
20
+ Page * inStatusPageField `json:"page"`
21
+ }
22
+
23
+ /*
24
+ * inStatusPage represents the way to connect to the API and retrieve a
25
+ * response.
26
+ */
27
+ type inStatusPage struct {
28
+ name string
29
+ apiURL string
30
+ data * inStatusResponse
31
+ }
32
+
33
+ /*
34
+ * Fetch pulls in a response from the API.
35
+ */
36
+ func (p * inStatusPage ) Fetch (c * http.Client ) error {
37
+
38
+ return fetchJSON (c , p .apiURL , & p .data )
39
+ }
40
+
41
+ func (p * inStatusPage ) Name () string {
42
+ return p .name
43
+ }
44
+
45
+ func (p * inStatusPage ) URL () string {
46
+ return p .apiURL
47
+ }
48
+
49
+ func (p * inStatusPage ) Status () (string , error ) {
50
+
51
+ if p .data == nil {
52
+ return "" , fmt .Errorf ("Data hasn't been retrieved." )
53
+ }
54
+
55
+ return p .data .Page .Status , nil
56
+ }
57
+
58
+ /*
59
+ * RegisterStatusPageIOPage creates a new provider.
60
+ */
61
+ func RegisterInStatusPage (name , apiURL string ) error {
62
+ return registerPage (& inStatusPage {name : name , apiURL : apiURL })
63
+ }
You can’t perform that action at this time.
0 commit comments