-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add snapshots endpoints. #108
Conversation
|
||
// Snapshot represents a DigitalOcean Snapshot | ||
type Snapshot struct { | ||
ID string `json:"id,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The snapshots API mixes the type here. It returns a string for volumes and an int for Droplets. A simple test programs that lists all snapshots errors for me with:
Something bad happened: json: cannot unmarshal number into Go value of type string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fixed in the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little closer, I'm still seeing the same error. ResourceType
is in the same situation, a string for volumes and an int for Droplets.
Here's the test program I'm using: https://gist.github.com/andrewsomething/d43ccaf333531001612647405188d4ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er, ResourceID maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opps, that's what I meant.
package godo | ||
|
||
import ( | ||
// "encoding/json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented out code
|
||
// ListVolume lists all the volume snapshots. | ||
func (s *SnapshotsServiceOp) ListVolume(opt *ListOptions) ([]Snapshot, *Response, error) { | ||
listOpt := listSnapshotOptions{ResourceType: "volume"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's existing code for volume snapshots, maybe it can be used. If not, it should be cleaned up if this is the implementation moving forward:
https://github.com/digitalocean/godo/blob/master/storage.go#L24-L38
and
https://github.com/digitalocean/godo/blob/master/storage.go#L153-L252
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that code is all still relevant!
That code refers to api.digitalocean.com/v2/volumes/$VOLUME_ID/snapshots
and api.digitalocean.com/v2/volumes/$VOLUME_ID/snapshots/$SNAPSHOT_ID
, while this code refers to api.digitalocean.com/v2/snapshots/$SNAPSHOT_ID
. Both sets of endpoints now exist.
However, I'll do a followup PR to remove all Beta
for the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, hm, https://github.com/digitalocean/godo/blob/master/storage.go#L153-L172 maybe should be removed as dupe.
type Snapshot struct { | ||
ID string `json:"id,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
ResourceID string `json:"type,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate JSON tag here
ResourceType string `json:"type,omitempty"` | ||
Regions []string `json:"regions,omitempty"` | ||
MinDiskSize int `json:"min_disk_size,omitempty"` | ||
SizeGigabytes int `json:"size_gigabytes,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the rest of the code uses SizeGigaBytes
(capitalized B
):
ResourceID string `json:"type,omitempty"` | ||
ResourceType string `json:"type,omitempty"` | ||
Regions []string `json:"regions,omitempty"` | ||
MinDiskSize int `json:"min_disk_size,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field lacks a unit and order of magnitude qualifier: _bytes
or _gigabytes
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup - we messed up when introducing in the API. We've called it MinDiskSize
in other spots in godo as well. It's GB though, I can open an issue to clarify the naming in godo across the board.
ea74695
to
2d57369
Compare
2d57369
to
e715166
Compare
Cleaned up! Anyone want to take another look? |
SizeGigaBytes: 100, | ||
CreatedAt: time.Date(2002, 10, 02, 15, 00, 00, 50000000, time.UTC), | ||
Created: "2002-10-02T15:00:00.05Z", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to use string
instead of time.Time
? Usually typed things > string things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, looks like we're mixed between strings and time.Time
and Created
vs. CreatedAt
:
Line 56 in 2ff8a02
CreatedAt time.Time `json:"created_at"` Line 39 in 5c91372
Created string `json:"created_at,omitempty"` Line 55 in c3a2aad
Created string `json:"created_at,omitempty"`
I can do another PR to standardize the others, what do you think of settling on Created
as a time.Time
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, defly should all be time.Time
LGTM |
https://developers.digitalocean.com/documentation/changelog/api-v2/add-volume-snapshots/
cc @andrewsomething @mikejholly @mjsteger