From de59235b17af4ee1c9b46ef934feac71569570df Mon Sep 17 00:00:00 2001 From: bryanl Date: Mon, 1 Jun 2015 10:44:30 -0400 Subject: [PATCH] updating documentation for godo --- droplet_actions.go | 18 +++++++++--------- droplets.go | 22 +++++++++++++--------- godo_test.go | 10 +++++----- images.go | 16 ++++++++-------- keys.go | 4 ++-- links.go | 1 + 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/droplet_actions.go b/droplet_actions.go index dd17b10..1df8eac 100644 --- a/droplet_actions.go +++ b/droplet_actions.go @@ -103,7 +103,7 @@ func (s *DropletActionsServiceOp) Rename(id int, name string) (*Action, *Respons return s.doAction(id, request) } -// Snapshot a Droplet +// Snapshot a Droplet. func (s *DropletActionsServiceOp) Snapshot(id int, name string) (*Action, *Response, error) { requestType := "snapshot" request := &ActionRequest{ @@ -113,49 +113,49 @@ func (s *DropletActionsServiceOp) Snapshot(id int, name string) (*Action, *Respo return s.doAction(id, request) } -// Disable backups for a droplet +// DisableBackups disables backups for a droplet. func (s *DropletActionsServiceOp) DisableBackups(id int) (*Action, *Response, error) { request := &ActionRequest{"type": "disable_backups"} return s.doAction(id, request) } -// Reset password for a droplet +// PasswordReset resets the password for a droplet. func (s *DropletActionsServiceOp) PasswordReset(id int) (*Action, *Response, error) { request := &ActionRequest{"type": "password_reset"} return s.doAction(id, request) } -// Rebuild droplet from an image with a given id +// RebuildByImageID rebuilds a droplet droplet from an image with a given id. func (s *DropletActionsServiceOp) RebuildByImageID(id, imageID int) (*Action, *Response, error) { request := &ActionRequest{"type": "rebuild", "image": imageID} return s.doAction(id, request) } -// Rebuild a droplet from an image with a given slug +// RebuildByImageSlug rebuilds a droplet from an image with a given slug. func (s *DropletActionsServiceOp) RebuildByImageSlug(id int, slug string) (*Action, *Response, error) { request := &ActionRequest{"type": "rebuild", "image": slug} return s.doAction(id, request) } -// Change a droplet kernel +// ChangeKernel changes the kernel for a droplet. func (s *DropletActionsServiceOp) ChangeKernel(id, kernelID int) (*Action, *Response, error) { request := &ActionRequest{"type": "change_kernel", "kernel": kernelID} return s.doAction(id, request) } -// Enable IPv6 on a droplet +// EnableIPv6 enables IPv6 for a droplet. func (s *DropletActionsServiceOp) EnableIPv6(id int) (*Action, *Response, error) { request := &ActionRequest{"type": "enable_ipv6"} return s.doAction(id, request) } -// Enable private networking on a droplet +// EnablePrivateNetworking enables private networking for a droplet. func (s *DropletActionsServiceOp) EnablePrivateNetworking(id int) (*Action, *Response, error) { request := &ActionRequest{"type": "enable_private_networking"} return s.doAction(id, request) } -// Upgrade a droplet +// Upgrade a droplet. func (s *DropletActionsServiceOp) Upgrade(id int) (*Action, *Response, error) { request := &ActionRequest{"type": "upgrade"} return s.doAction(id, request) diff --git a/droplets.go b/droplets.go index 8f66bb2..2818963 100644 --- a/droplets.go +++ b/droplets.go @@ -95,12 +95,14 @@ 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) - } else { - return json.Marshal(d.ID) } + + return json.Marshal(d.ID) } // DropletCreateSSHKey identifies a SSH Key for the create request. It prefers fingerprint over ID. @@ -109,12 +111,14 @@ type DropletCreateSSHKey struct { Fingerprint string } +// MarshalJSON returns either the fingerprint or id of the ssh key. It returns +// the id if the fingerprint is empty. func (d DropletCreateSSHKey) MarshalJSON() ([]byte, error) { if d.Fingerprint != "" { return json.Marshal(d.Fingerprint) - } else { - return json.Marshal(d.ID) } + + return json.Marshal(d.ID) } // DropletCreateRequest represents a request to create a droplet. @@ -242,7 +246,7 @@ func (s *DropletsServiceOp) Delete(dropletID int) (*Response, error) { return resp, err } -// List droplet available kernels +// Kernels lists kernels available for a droplet. func (s *DropletsServiceOp) Kernels(dropletID int, opt *ListOptions) ([]Kernel, *Response, error) { path := fmt.Sprintf("%s/%d/kernels", dropletBasePath, dropletID) path, err := addOptions(path, opt) @@ -264,7 +268,7 @@ func (s *DropletsServiceOp) Kernels(dropletID int, opt *ListOptions) ([]Kernel, return root.Kernels, resp, err } -// List droplet actions +// Actions lists the actions for a droplet. func (s *DropletsServiceOp) Actions(dropletID int, opt *ListOptions) ([]Action, *Response, error) { path := fmt.Sprintf("%s/%d/actions", dropletBasePath, dropletID) path, err := addOptions(path, opt) @@ -289,7 +293,7 @@ func (s *DropletsServiceOp) Actions(dropletID int, opt *ListOptions) ([]Action, return root.Actions, resp, err } -// List droplet backups +// Backups lists the backups for a droplet. func (s *DropletsServiceOp) Backups(dropletID int, opt *ListOptions) ([]Image, *Response, error) { path := fmt.Sprintf("%s/%d/backups", dropletBasePath, dropletID) path, err := addOptions(path, opt) @@ -314,7 +318,7 @@ func (s *DropletsServiceOp) Backups(dropletID int, opt *ListOptions) ([]Image, * return root.Backups, resp, err } -// List droplet snapshots +// Snapshots lists the snapshots available for a droplet. func (s *DropletsServiceOp) Snapshots(dropletID int, opt *ListOptions) ([]Image, *Response, error) { path := fmt.Sprintf("%s/%d/snapshots", dropletBasePath, dropletID) path, err := addOptions(path, opt) @@ -339,7 +343,7 @@ func (s *DropletsServiceOp) Snapshots(dropletID int, opt *ListOptions) ([]Image, return root.Snapshots, resp, err } -// List droplet neighbors +// Neighbors lists the neighbors for a droplet. func (s *DropletsServiceOp) Neighbors(dropletID int) ([]Droplet, *Response, error) { path := fmt.Sprintf("%s/%d/neighbors", dropletBasePath, dropletID) diff --git a/godo_test.go b/godo_test.go index b884f40..5da13f9 100644 --- a/godo_test.go +++ b/godo_test.go @@ -430,24 +430,24 @@ func TestAddOptions(t *testing.T) { continue } - gotUrl, err := url.Parse(got) + gotURL, err := url.Parse(got) if err != nil { t.Errorf("%q unable to parse returned URL", c.name) continue } - expectedUrl, err := url.Parse(c.expected) + expectedURL, err := url.Parse(c.expected) if err != nil { t.Errorf("%q unable to parse expected URL", c.name) continue } - if g, e := gotUrl.Path, expectedUrl.Path; g != e { - t.Errorf("%q path = %q; expected %q", g, e) + if g, e := gotURL.Path, expectedURL.Path; g != e { + t.Errorf("%q path = %q; expected %q", c.name, g, e) continue } - if g, e := gotUrl.Query(), expectedUrl.Query(); !reflect.DeepEqual(g, e) { + if g, e := gotURL.Query(), expectedURL.Query(); !reflect.DeepEqual(g, e) { t.Errorf("%q query = %#v; expected %#v", c.name, g, e) continue } diff --git a/images.go b/images.go index 741324f..dda8b6c 100644 --- a/images.go +++ b/images.go @@ -61,40 +61,40 @@ func (i Image) String() string { return Stringify(i) } -// List all images +// List lists all the images available. func (s *ImagesServiceOp) List(opt *ListOptions) ([]Image, *Response, error) { return s.list(opt, nil) } -// List distribution images +// ListDistribution lists all the distribution images. func (s *ImagesServiceOp) ListDistribution(opt *ListOptions) ([]Image, *Response, error) { listOpt := listImageOptions{Type: "distribution"} return s.list(opt, &listOpt) } -// List application images +// ListApplication lists all the application images. func (s *ImagesServiceOp) ListApplication(opt *ListOptions) ([]Image, *Response, error) { listOpt := listImageOptions{Type: "application"} return s.list(opt, &listOpt) } -// List user images +// ListUser lists all the user images. func (s *ImagesServiceOp) ListUser(opt *ListOptions) ([]Image, *Response, error) { listOpt := listImageOptions{Private: true} return s.list(opt, &listOpt) } -// Get individual image by id +// GetByID retrieves an image by id. func (s *ImagesServiceOp) GetByID(imageID int) (*Image, *Response, error) { return s.get(interface{}(imageID)) } -// Get individual image by slug +// GetBySlug retrieves an image by slug. func (s *ImagesServiceOp) GetBySlug(slug string) (*Image, *Response, error) { return s.get(interface{}(slug)) } -// Update an image name +// Update an image name. func (s *ImagesServiceOp) Update(imageID int, updateRequest *ImageUpdateRequest) (*Image, *Response, error) { path := fmt.Sprintf("%s/%d", imageBasePath, imageID) req, err := s.client.NewRequest("PUT", path, updateRequest) @@ -111,7 +111,7 @@ func (s *ImagesServiceOp) Update(imageID int, updateRequest *ImageUpdateRequest) return &root.Image, resp, err } -// Delete image +// Delete an image. func (s *ImagesServiceOp) Delete(imageID int) (*Response, error) { path := fmt.Sprintf("%s/%d", imageBasePath, imageID) diff --git a/keys.go b/keys.go index ae0b5af..355c75b 100644 --- a/keys.go +++ b/keys.go @@ -127,7 +127,7 @@ func (s *KeysServiceOp) Create(createRequest *KeyCreateRequest) (*Key, *Response return &root.SSHKey, resp, err } -// Update a key name by ID +// UpdateByID updates a key name by ID. func (s *KeysServiceOp) UpdateByID(keyID int, updateRequest *KeyUpdateRequest) (*Key, *Response, error) { path := fmt.Sprintf("%s/%d", keysBasePath, keyID) req, err := s.client.NewRequest("PUT", path, updateRequest) @@ -144,7 +144,7 @@ func (s *KeysServiceOp) UpdateByID(keyID int, updateRequest *KeyUpdateRequest) ( return &root.SSHKey, resp, err } -// Update a key name by fingerprint +// UpdateByFingerprint updates a key name by fingerprint. func (s *KeysServiceOp) UpdateByFingerprint(fingerprint string, updateRequest *KeyUpdateRequest) (*Key, *Response, error) { path := fmt.Sprintf("%s/%s", keysBasePath, fingerprint) req, err := s.client.NewRequest("PUT", path, updateRequest) diff --git a/links.go b/links.go index 64db34c..4635105 100644 --- a/links.go +++ b/links.go @@ -80,6 +80,7 @@ func pageForURL(urlText string) (int, error) { return page, nil } +// Get a link action by id. func (la *LinkAction) Get(client *Client) (*Action, *Response, error) { return client.Actions.Get(la.ID) }