-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrain.go
128 lines (106 loc) · 3.68 KB
/
frain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package frain
import (
"errors"
"fmt"
"strconv"
"strings"
"time"
)
var (
// Version represents the current version of this program
Version string
)
// Page specifies the developer tool to check. The Name field here is essentially akin
// to Name field already defined in Service, Component, Incident and IncidentUpdate.
type Page struct {
Name string `json:"name"`
Service *Service `json:"service"`
}
// Service represents an external service that we intend to check for availability
type Service struct {
ID string `json:"id"`
Name string `json:"name"`
PageID string `json:"pageId"`
Status string `json:"status"`
StatusPageURL string `json:"statusPageUrl"`
Provider string `json:"provider"`
Description string `json:"description"`
Indicator string `json:"indicator"`
IsActive bool `json:"isActive"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Components []Component `json:"components"`
Incidents []Incident `json:"incidents"`
HighLevelComponents []SubComponents `json:"highLevelComponents"`
}
// Component contains information about a service's components
type Component struct {
ID string `json:"id"`
Name string `json:"name"`
ServiceID string `json:"serviceId"`
ComponentID string `json:"componentId"`
Status string `json:"status"`
Description string `json:"description"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// Incident gives all neccessary information relating to a single incident
type Incident struct {
ID string `json:"id"`
Name string `json:"name"`
ServiceID string `json:"serviceId"`
IncidentID string `json:"incidentId"`
Status string `json:"status"`
Impact string `json:"impact"`
Shortlink string `json:"shortlink"`
IsActive bool `json:"isActive"`
ResolvedAt time.Time `json:"resolvedAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
IncidentUpdates []IncidentUpdate `json:"incidentUpdates"`
}
// IncidentUpdate provides an update to an existing incident
type IncidentUpdate struct {
ID string `json:"id"`
Name string `json:"name"`
IncidentUpdateID string `json:"incidentUpdateId"`
IncidentID string `json:"incidentId"`
Status string `json:"status"`
Body string `json:"body"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// SubComponents is similar to Components with the added nesting feature
type SubComponents struct {
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Description string `json:"description"`
SubComponents []SubComponents `json:"subComponents"`
}
// Init is a simple method to print various build info
func Init() {
fmt.Println(fmt.Sprintf("Frain version %s", Version))
fmt.Println("\nA status checker for various developer tools.")
}
// CleanTimeArg takes in a time construct in string format and ensures it is accurate else
// it returns an error
func CleanTimeArg(t string) (string, error) {
yMd := strings.Split(t, "-")
if len(yMd) != 3 {
return "", errors.New("time must have the format: YYYY-MM-DD")
}
y, err := strconv.Atoi(yMd[0])
if err != nil {
return "", errors.New(fmt.Sprint("failed to parse year arg in ", t))
}
M, err := strconv.Atoi(yMd[1])
if err != nil {
return "", errors.New(fmt.Sprint("failed to parse month arg in ", t))
}
d, err := strconv.Atoi(yMd[2])
if err != nil {
return "", errors.New(fmt.Sprint("failed to parse day arg in ", t))
}
return fmt.Sprintf("%04d-%02d-%02d", y, M, d), nil
}