@@ -3,7 +3,6 @@ package linodego
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
- "fmt"
7
6
"time"
8
7
9
8
"github.com/linode/linodego/internal/parseabletime"
@@ -88,64 +87,57 @@ func (i *InstanceSnapshot) UnmarshalJSON(b []byte) error {
88
87
89
88
// GetInstanceSnapshot gets the snapshot with the provided ID
90
89
func (c * Client ) GetInstanceSnapshot (ctx context.Context , linodeID int , snapshotID int ) (* InstanceSnapshot , error ) {
91
- e := fmt .Sprintf ("linode/instances/%d/backups/%d" , linodeID , snapshotID )
92
- req := c .R (ctx ).SetResult (& InstanceSnapshot {})
93
- r , err := coupleAPIErrors (req .Get (e ))
90
+ e := formatAPIPath ("linode/instances/%d/backups/%d" , linodeID , snapshotID )
91
+ response , err := doGETRequest [InstanceSnapshot ](ctx , c , e )
94
92
if err != nil {
95
93
return nil , err
96
94
}
97
- return r .Result ().(* InstanceSnapshot ), nil
95
+
96
+ return response , nil
98
97
}
99
98
100
99
// CreateInstanceSnapshot Creates or Replaces the snapshot Backup of a Linode. If a previous snapshot exists for this Linode, it will be deleted.
101
100
func (c * Client ) CreateInstanceSnapshot (ctx context.Context , linodeID int , label string ) (* InstanceSnapshot , error ) {
102
- body , err := json .Marshal (map [string ]string {"label" : label })
103
- if err != nil {
104
- return nil , err
105
- }
106
- e := fmt .Sprintf ("linode/instances/%d/backups" , linodeID )
107
- req := c .R (ctx ).SetResult (& InstanceSnapshot {}).SetBody (string (body ))
108
- r , err := coupleAPIErrors (req .Post (e ))
101
+ opts := map [string ]string {"label" : label }
102
+
103
+ e := formatAPIPath ("linode/instances/%d/backups" , linodeID )
104
+ response , err := doPOSTRequest [InstanceSnapshot ](ctx , c , e , opts )
109
105
if err != nil {
110
106
return nil , err
111
107
}
112
108
113
- return r . Result ().( * InstanceSnapshot ) , nil
109
+ return response , nil
114
110
}
115
111
116
112
// GetInstanceBackups gets the Instance's available Backups.
117
113
// This is not called ListInstanceBackups because a single object is returned, matching the API response.
118
114
func (c * Client ) GetInstanceBackups (ctx context.Context , linodeID int ) (* InstanceBackupsResponse , error ) {
119
- e := fmt .Sprintf ("linode/instances/%d/backups" , linodeID )
120
- req := c .R (ctx ).SetResult (& InstanceBackupsResponse {})
121
- r , err := coupleAPIErrors (req .Get (e ))
115
+ e := formatAPIPath ("linode/instances/%d/backups" , linodeID )
116
+ response , err := doGETRequest [InstanceBackupsResponse ](ctx , c , e )
122
117
if err != nil {
123
118
return nil , err
124
119
}
125
- return r .Result ().(* InstanceBackupsResponse ), nil
120
+
121
+ return response , nil
126
122
}
127
123
128
124
// EnableInstanceBackups Enables backups for the specified Linode.
129
125
func (c * Client ) EnableInstanceBackups (ctx context.Context , linodeID int ) error {
130
- e := fmt . Sprintf ("linode/instances/%d/backups/enable" , linodeID )
131
- _ , err := coupleAPIErrors ( c . R ( ctx ). Post ( e ) )
126
+ e := formatAPIPath ("linode/instances/%d/backups/enable" , linodeID )
127
+ _ , err := doPOSTRequest [ InstanceBackup , any ]( ctx , c , e )
132
128
return err
133
129
}
134
130
135
131
// CancelInstanceBackups Cancels backups for the specified Linode.
136
132
func (c * Client ) CancelInstanceBackups (ctx context.Context , linodeID int ) error {
137
- e := fmt . Sprintf ("linode/instances/%d/backups/cancel" , linodeID )
138
- _ , err := coupleAPIErrors ( c . R ( ctx ). Post ( e ) )
133
+ e := formatAPIPath ("linode/instances/%d/backups/cancel" , linodeID )
134
+ _ , err := doPOSTRequest [ InstanceBackup , any ]( ctx , c , e )
139
135
return err
140
136
}
141
137
142
138
// RestoreInstanceBackup Restores a Linode's Backup to the specified Linode.
143
139
func (c * Client ) RestoreInstanceBackup (ctx context.Context , linodeID int , backupID int , opts RestoreInstanceOptions ) error {
144
- body , err := json .Marshal (opts )
145
- if err != nil {
146
- return NewError (err )
147
- }
148
- e := fmt .Sprintf ("linode/instances/%d/backups/%d/restore" , linodeID , backupID )
149
- _ , err = coupleAPIErrors (c .R (ctx ).SetBody (string (body )).Post (e ))
140
+ e := formatAPIPath ("linode/instances/%d/backups/%d/restore" , linodeID , backupID )
141
+ _ , err := doPOSTRequest [InstanceBackup ](ctx , c , e , opts )
150
142
return err
151
143
}
0 commit comments