-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreport.go
More file actions
54 lines (45 loc) · 1.19 KB
/
report.go
File metadata and controls
54 lines (45 loc) · 1.19 KB
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
package main
import (
"encoding/json"
"time"
)
type resources []Resource
type Report struct {
Time time.Time `json:"timestamp"`
Found resources `json:"found"`
Deleted resources `json:"deleted"`
FailedToDelete resources `json:"failed_to_delete"`
}
func (rep *Report) AddFound(r Resource) {
rep.Found = append(rep.Found, r)
}
func (rep *Report) AddDeleted(r Resource) {
rep.Deleted = append(rep.Deleted, r)
}
func (rep *Report) AddFailedToDelete(r Resource) {
rep.FailedToDelete = append(rep.FailedToDelete, r)
}
func (res resources) MarshalJSON() ([]byte, error) {
type resourcePrinter struct {
ClusterID string `json:"cluster_id,omitempty"`
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
Name string `json:"name"`
Type string `json:"type"`
}
printers := make([]resourcePrinter, len(res))
for i := range res {
var clusterID string
if c, ok := res[i].(Clusterer); ok {
clusterID = c.ClusterID()
}
printers[i] = resourcePrinter{
ClusterID: clusterID,
ID: res[i].ID(),
CreatedAt: res[i].CreatedAt(),
Name: res[i].Name(),
Type: res[i].Type(),
}
}
return json.Marshal(printers)
}