Skip to content
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

Merged
merged 1 commit into from
Nov 30, 2016
Merged

Add snapshots endpoints. #108

merged 1 commit into from
Nov 30, 2016

Conversation


// Snapshot represents a DigitalOcean Snapshot
type Snapshot struct {
ID string `json:"id,omitempty"`
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, ResourceID maybe?

Copy link
Member

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"
Copy link
Contributor

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"}
Copy link
Contributor

@aybabtme aybabtme Nov 16, 2016

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

Copy link
Contributor Author

@phillbaker phillbaker Nov 17, 2016

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type Snapshot struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
ResourceID string `json:"type,omitempty"`
Copy link
Contributor

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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResourceID string `json:"type,omitempty"`
ResourceType string `json:"type,omitempty"`
Regions []string `json:"regions,omitempty"`
MinDiskSize int `json:"min_disk_size,omitempty"`
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@phillbaker
Copy link
Contributor Author

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",
Copy link
Contributor

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.

Copy link
Contributor Author

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:

I can do another PR to standardize the others, what do you think of settling on Created as a time.Time?

Copy link
Contributor

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

@aybabtme
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants