-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathbackups.go
52 lines (46 loc) · 1.16 KB
/
backups.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
package linodego
import (
"fmt"
)
// InstanceBackupsResponse response struct for backup snapshot
type InstanceBackupsResponse struct {
Automatic []*InstanceSnapshot
Snapshot *InstanceBackupSnapshotResponse
}
type InstanceBackupSnapshotResponse struct {
Current *InstanceSnapshot
InProgress *InstanceSnapshot `json:"in_progress"`
}
// GetInstanceBackups gets the Instance's available Backups
func (c *Client) GetInstanceBackups(linodeID int) (*InstanceBackupsResponse, error) {
e, err := c.Instances.Endpoint()
if err != nil {
return nil, err
}
e = fmt.Sprintf("%s/%d/backups", e, linodeID)
r, err := coupleAPIErrors(c.R().
SetResult(&InstanceBackupsResponse{}).
Get(e))
if err != nil {
return nil, err
}
return r.Result().(*InstanceBackupsResponse).fixDates(), nil
}
func (l *InstanceBackupSnapshotResponse) fixDates() *InstanceBackupSnapshotResponse {
if l.Current != nil {
l.Current.fixDates()
}
if l.InProgress != nil {
l.InProgress.fixDates()
}
return l
}
func (l *InstanceBackupsResponse) fixDates() *InstanceBackupsResponse {
for _, el := range l.Automatic {
el.fixDates()
}
if l.Snapshot != nil {
l.Snapshot.fixDates()
}
return l
}