updating documentation for godo

This commit is contained in:
bryanl 2015-06-01 10:44:30 -04:00
parent 1df42b98f6
commit de59235b17
6 changed files with 38 additions and 33 deletions

View File

@ -103,7 +103,7 @@ func (s *DropletActionsServiceOp) Rename(id int, name string) (*Action, *Respons
return s.doAction(id, request) return s.doAction(id, request)
} }
// Snapshot a Droplet // Snapshot a Droplet.
func (s *DropletActionsServiceOp) Snapshot(id int, name string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) Snapshot(id int, name string) (*Action, *Response, error) {
requestType := "snapshot" requestType := "snapshot"
request := &ActionRequest{ request := &ActionRequest{
@ -113,49 +113,49 @@ func (s *DropletActionsServiceOp) Snapshot(id int, name string) (*Action, *Respo
return s.doAction(id, request) 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) { func (s *DropletActionsServiceOp) DisableBackups(id int) (*Action, *Response, error) {
request := &ActionRequest{"type": "disable_backups"} request := &ActionRequest{"type": "disable_backups"}
return s.doAction(id, request) 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) { func (s *DropletActionsServiceOp) PasswordReset(id int) (*Action, *Response, error) {
request := &ActionRequest{"type": "password_reset"} request := &ActionRequest{"type": "password_reset"}
return s.doAction(id, request) 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) { func (s *DropletActionsServiceOp) RebuildByImageID(id, imageID int) (*Action, *Response, error) {
request := &ActionRequest{"type": "rebuild", "image": imageID} request := &ActionRequest{"type": "rebuild", "image": imageID}
return s.doAction(id, request) 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) { func (s *DropletActionsServiceOp) RebuildByImageSlug(id int, slug string) (*Action, *Response, error) {
request := &ActionRequest{"type": "rebuild", "image": slug} request := &ActionRequest{"type": "rebuild", "image": slug}
return s.doAction(id, request) 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) { func (s *DropletActionsServiceOp) ChangeKernel(id, kernelID int) (*Action, *Response, error) {
request := &ActionRequest{"type": "change_kernel", "kernel": kernelID} request := &ActionRequest{"type": "change_kernel", "kernel": kernelID}
return s.doAction(id, request) 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) { func (s *DropletActionsServiceOp) EnableIPv6(id int) (*Action, *Response, error) {
request := &ActionRequest{"type": "enable_ipv6"} request := &ActionRequest{"type": "enable_ipv6"}
return s.doAction(id, request) 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) { func (s *DropletActionsServiceOp) EnablePrivateNetworking(id int) (*Action, *Response, error) {
request := &ActionRequest{"type": "enable_private_networking"} request := &ActionRequest{"type": "enable_private_networking"}
return s.doAction(id, request) return s.doAction(id, request)
} }
// Upgrade a droplet // Upgrade a droplet.
func (s *DropletActionsServiceOp) Upgrade(id int) (*Action, *Response, error) { func (s *DropletActionsServiceOp) Upgrade(id int) (*Action, *Response, error) {
request := &ActionRequest{"type": "upgrade"} request := &ActionRequest{"type": "upgrade"}
return s.doAction(id, request) return s.doAction(id, request)

View File

@ -95,12 +95,14 @@ type DropletCreateImage struct {
Slug string 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) { func (d DropletCreateImage) MarshalJSON() ([]byte, error) {
if d.Slug != "" { if d.Slug != "" {
return json.Marshal(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. // DropletCreateSSHKey identifies a SSH Key for the create request. It prefers fingerprint over ID.
@ -109,12 +111,14 @@ type DropletCreateSSHKey struct {
Fingerprint string 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) { func (d DropletCreateSSHKey) MarshalJSON() ([]byte, error) {
if d.Fingerprint != "" { if d.Fingerprint != "" {
return json.Marshal(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. // DropletCreateRequest represents a request to create a droplet.
@ -242,7 +246,7 @@ func (s *DropletsServiceOp) Delete(dropletID int) (*Response, error) {
return resp, err 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) { func (s *DropletsServiceOp) Kernels(dropletID int, opt *ListOptions) ([]Kernel, *Response, error) {
path := fmt.Sprintf("%s/%d/kernels", dropletBasePath, dropletID) path := fmt.Sprintf("%s/%d/kernels", dropletBasePath, dropletID)
path, err := addOptions(path, opt) path, err := addOptions(path, opt)
@ -264,7 +268,7 @@ func (s *DropletsServiceOp) Kernels(dropletID int, opt *ListOptions) ([]Kernel,
return root.Kernels, resp, err 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) { func (s *DropletsServiceOp) Actions(dropletID int, opt *ListOptions) ([]Action, *Response, error) {
path := fmt.Sprintf("%s/%d/actions", dropletBasePath, dropletID) path := fmt.Sprintf("%s/%d/actions", dropletBasePath, dropletID)
path, err := addOptions(path, opt) path, err := addOptions(path, opt)
@ -289,7 +293,7 @@ func (s *DropletsServiceOp) Actions(dropletID int, opt *ListOptions) ([]Action,
return root.Actions, resp, err 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) { func (s *DropletsServiceOp) Backups(dropletID int, opt *ListOptions) ([]Image, *Response, error) {
path := fmt.Sprintf("%s/%d/backups", dropletBasePath, dropletID) path := fmt.Sprintf("%s/%d/backups", dropletBasePath, dropletID)
path, err := addOptions(path, opt) path, err := addOptions(path, opt)
@ -314,7 +318,7 @@ func (s *DropletsServiceOp) Backups(dropletID int, opt *ListOptions) ([]Image, *
return root.Backups, resp, err 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) { func (s *DropletsServiceOp) Snapshots(dropletID int, opt *ListOptions) ([]Image, *Response, error) {
path := fmt.Sprintf("%s/%d/snapshots", dropletBasePath, dropletID) path := fmt.Sprintf("%s/%d/snapshots", dropletBasePath, dropletID)
path, err := addOptions(path, opt) path, err := addOptions(path, opt)
@ -339,7 +343,7 @@ func (s *DropletsServiceOp) Snapshots(dropletID int, opt *ListOptions) ([]Image,
return root.Snapshots, resp, err return root.Snapshots, resp, err
} }
// List droplet neighbors // Neighbors lists the neighbors for a droplet.
func (s *DropletsServiceOp) Neighbors(dropletID int) ([]Droplet, *Response, error) { func (s *DropletsServiceOp) Neighbors(dropletID int) ([]Droplet, *Response, error) {
path := fmt.Sprintf("%s/%d/neighbors", dropletBasePath, dropletID) path := fmt.Sprintf("%s/%d/neighbors", dropletBasePath, dropletID)

View File

@ -430,24 +430,24 @@ func TestAddOptions(t *testing.T) {
continue continue
} }
gotUrl, err := url.Parse(got) gotURL, err := url.Parse(got)
if err != nil { if err != nil {
t.Errorf("%q unable to parse returned URL", c.name) t.Errorf("%q unable to parse returned URL", c.name)
continue continue
} }
expectedUrl, err := url.Parse(c.expected) expectedURL, err := url.Parse(c.expected)
if err != nil { if err != nil {
t.Errorf("%q unable to parse expected URL", c.name) t.Errorf("%q unable to parse expected URL", c.name)
continue continue
} }
if g, e := gotUrl.Path, expectedUrl.Path; g != e { if g, e := gotURL.Path, expectedURL.Path; g != e {
t.Errorf("%q path = %q; expected %q", g, e) t.Errorf("%q path = %q; expected %q", c.name, g, e)
continue 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) t.Errorf("%q query = %#v; expected %#v", c.name, g, e)
continue continue
} }

View File

@ -61,40 +61,40 @@ func (i Image) String() string {
return Stringify(i) return Stringify(i)
} }
// List all images // List lists all the images available.
func (s *ImagesServiceOp) List(opt *ListOptions) ([]Image, *Response, error) { func (s *ImagesServiceOp) List(opt *ListOptions) ([]Image, *Response, error) {
return s.list(opt, nil) return s.list(opt, nil)
} }
// List distribution images // ListDistribution lists all the distribution images.
func (s *ImagesServiceOp) ListDistribution(opt *ListOptions) ([]Image, *Response, error) { func (s *ImagesServiceOp) ListDistribution(opt *ListOptions) ([]Image, *Response, error) {
listOpt := listImageOptions{Type: "distribution"} listOpt := listImageOptions{Type: "distribution"}
return s.list(opt, &listOpt) return s.list(opt, &listOpt)
} }
// List application images // ListApplication lists all the application images.
func (s *ImagesServiceOp) ListApplication(opt *ListOptions) ([]Image, *Response, error) { func (s *ImagesServiceOp) ListApplication(opt *ListOptions) ([]Image, *Response, error) {
listOpt := listImageOptions{Type: "application"} listOpt := listImageOptions{Type: "application"}
return s.list(opt, &listOpt) return s.list(opt, &listOpt)
} }
// List user images // ListUser lists all the user images.
func (s *ImagesServiceOp) ListUser(opt *ListOptions) ([]Image, *Response, error) { func (s *ImagesServiceOp) ListUser(opt *ListOptions) ([]Image, *Response, error) {
listOpt := listImageOptions{Private: true} listOpt := listImageOptions{Private: true}
return s.list(opt, &listOpt) 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) { func (s *ImagesServiceOp) GetByID(imageID int) (*Image, *Response, error) {
return s.get(interface{}(imageID)) 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) { func (s *ImagesServiceOp) GetBySlug(slug string) (*Image, *Response, error) {
return s.get(interface{}(slug)) return s.get(interface{}(slug))
} }
// Update an image name // Update an image name.
func (s *ImagesServiceOp) Update(imageID int, updateRequest *ImageUpdateRequest) (*Image, *Response, error) { func (s *ImagesServiceOp) Update(imageID int, updateRequest *ImageUpdateRequest) (*Image, *Response, error) {
path := fmt.Sprintf("%s/%d", imageBasePath, imageID) path := fmt.Sprintf("%s/%d", imageBasePath, imageID)
req, err := s.client.NewRequest("PUT", path, updateRequest) 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 return &root.Image, resp, err
} }
// Delete image // Delete an image.
func (s *ImagesServiceOp) Delete(imageID int) (*Response, error) { func (s *ImagesServiceOp) Delete(imageID int) (*Response, error) {
path := fmt.Sprintf("%s/%d", imageBasePath, imageID) path := fmt.Sprintf("%s/%d", imageBasePath, imageID)

View File

@ -127,7 +127,7 @@ func (s *KeysServiceOp) Create(createRequest *KeyCreateRequest) (*Key, *Response
return &root.SSHKey, resp, err 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) { func (s *KeysServiceOp) UpdateByID(keyID int, updateRequest *KeyUpdateRequest) (*Key, *Response, error) {
path := fmt.Sprintf("%s/%d", keysBasePath, keyID) path := fmt.Sprintf("%s/%d", keysBasePath, keyID)
req, err := s.client.NewRequest("PUT", path, updateRequest) 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 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) { func (s *KeysServiceOp) UpdateByFingerprint(fingerprint string, updateRequest *KeyUpdateRequest) (*Key, *Response, error) {
path := fmt.Sprintf("%s/%s", keysBasePath, fingerprint) path := fmt.Sprintf("%s/%s", keysBasePath, fingerprint)
req, err := s.client.NewRequest("PUT", path, updateRequest) req, err := s.client.NewRequest("PUT", path, updateRequest)

View File

@ -80,6 +80,7 @@ func pageForURL(urlText string) (int, error) {
return page, nil return page, nil
} }
// Get a link action by id.
func (la *LinkAction) Get(client *Client) (*Action, *Response, error) { func (la *LinkAction) Get(client *Client) (*Action, *Response, error) {
return client.Actions.Get(la.ID) return client.Actions.Get(la.ID)
} }