Skip to content

Commit

Permalink
Merge pull request digitalocean#104 from chaseadamsio/cleanup-createI…
Browse files Browse the repository at this point in the history
…mageMarshalJSON

organizes dropletCreateImage MarshalJSON declaration
  • Loading branch information
bryanl authored Sep 9, 2016
2 parents 9ce324a + eaefd48 commit 2ff8a02
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions droplets.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ type DropletCreateImage struct {
Slug string
}

// MarshalJSON returns either the slug or id of the image. It returns the id
// if the slug is empty.
func (d DropletCreateImage) MarshalJSON() ([]byte, error) {
if d.Slug != "" {
return json.Marshal(d.Slug)
}

return json.Marshal(d.ID)
}

// DropletCreateVolume identifies a volume to attach for the create request. It
// prefers Name over ID,
type DropletCreateVolume struct {
Expand All @@ -168,16 +178,6 @@ func (d DropletCreateVolume) MarshalJSON() ([]byte, error) {
}{ID: d.ID})
}

// MarshalJSON returns either the slug or id of the image. It returns the id
// if the slug is empty.
func (d DropletCreateImage) MarshalJSON() ([]byte, error) {
if d.Slug != "" {
return json.Marshal(d.Slug)
}

return json.Marshal(d.ID)
}

// DropletCreateSSHKey identifies a SSH Key for the create request. It prefers fingerprint over ID.
type DropletCreateSSHKey struct {
ID int
Expand Down

0 comments on commit 2ff8a02

Please sign in to comment.