make linters happy

This commit is contained in:
Term1nal 2016-12-20 16:00:17 -08:00
parent 758b5be38e
commit b814e84f48
11 changed files with 129 additions and 113 deletions

View File

@ -8,7 +8,7 @@ import (
// ActionRequest reprents DigitalOcean Action Request // ActionRequest reprents DigitalOcean Action Request
type ActionRequest map[string]interface{} type ActionRequest map[string]interface{}
// DropletActionsService is an interface for interfacing with the droplet actions // DropletActionsService is an interface for interfacing with the Droplet actions
// endpoints of the DigitalOcean API // endpoints of the DigitalOcean API
// See: https://developers.digitalocean.com/documentation/v2#droplet-actions // See: https://developers.digitalocean.com/documentation/v2#droplet-actions
type DropletActionsService interface { type DropletActionsService interface {
@ -43,7 +43,7 @@ type DropletActionsService interface {
GetByURI(string) (*Action, *Response, error) GetByURI(string) (*Action, *Response, error)
} }
// DropletActionsServiceOp handles communication with the droplet action related // DropletActionsServiceOp handles communication with the Droplet action related
// methods of the DigitalOcean API. // methods of the DigitalOcean API.
type DropletActionsServiceOp struct { type DropletActionsServiceOp struct {
client *Client client *Client
@ -57,7 +57,7 @@ func (s *DropletActionsServiceOp) Shutdown(id int) (*Action, *Response, error) {
return s.doAction(id, request) return s.doAction(id, request)
} }
// Shutdown Droplets by Tag // ShutdownByTag shuts down Droplets matched by a Tag.
func (s *DropletActionsServiceOp) ShutdownByTag(tag string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) ShutdownByTag(tag string) (*Action, *Response, error) {
request := &ActionRequest{"type": "shutdown"} request := &ActionRequest{"type": "shutdown"}
return s.doActionByTag(tag, request) return s.doActionByTag(tag, request)
@ -69,7 +69,7 @@ func (s *DropletActionsServiceOp) PowerOff(id int) (*Action, *Response, error) {
return s.doAction(id, request) return s.doAction(id, request)
} }
// PowerOff a Droplet by Tag // PowerOffByTag powers off Droplets matched by a Tag.
func (s *DropletActionsServiceOp) PowerOffByTag(tag string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) PowerOffByTag(tag string) (*Action, *Response, error) {
request := &ActionRequest{"type": "power_off"} request := &ActionRequest{"type": "power_off"}
return s.doActionByTag(tag, request) return s.doActionByTag(tag, request)
@ -81,7 +81,7 @@ func (s *DropletActionsServiceOp) PowerOn(id int) (*Action, *Response, error) {
return s.doAction(id, request) return s.doAction(id, request)
} }
// PowerOn a Droplet by Tag // PowerOnByTag powers on Droplets matched by a Tag.
func (s *DropletActionsServiceOp) PowerOnByTag(tag string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) PowerOnByTag(tag string) (*Action, *Response, error) {
request := &ActionRequest{"type": "power_on"} request := &ActionRequest{"type": "power_on"}
return s.doActionByTag(tag, request) return s.doActionByTag(tag, request)
@ -93,7 +93,7 @@ func (s *DropletActionsServiceOp) PowerCycle(id int) (*Action, *Response, error)
return s.doAction(id, request) return s.doAction(id, request)
} }
// PowerCycle a Droplet by Tag // PowerCycleByTag power cycles Droplets matched by a Tag.
func (s *DropletActionsServiceOp) PowerCycleByTag(tag string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) PowerCycleByTag(tag string) (*Action, *Response, error) {
request := &ActionRequest{"type": "power_cycle"} request := &ActionRequest{"type": "power_cycle"}
return s.doActionByTag(tag, request) return s.doActionByTag(tag, request)
@ -146,7 +146,7 @@ func (s *DropletActionsServiceOp) Snapshot(id int, name string) (*Action, *Respo
return s.doAction(id, request) return s.doAction(id, request)
} }
// Snapshot a Droplet by Tag // SnapshotByTag snapshots Droplets matched by a Tag.
func (s *DropletActionsServiceOp) SnapshotByTag(tag string, name string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) SnapshotByTag(tag string, name string) (*Action, *Response, error) {
requestType := "snapshot" requestType := "snapshot"
request := &ActionRequest{ request := &ActionRequest{
@ -156,79 +156,79 @@ func (s *DropletActionsServiceOp) SnapshotByTag(tag string, name string) (*Actio
return s.doActionByTag(tag, request) return s.doActionByTag(tag, request)
} }
// EnableBackups enables backups for a droplet. // EnableBackups enables backups for a Droplet.
func (s *DropletActionsServiceOp) EnableBackups(id int) (*Action, *Response, error) { func (s *DropletActionsServiceOp) EnableBackups(id int) (*Action, *Response, error) {
request := &ActionRequest{"type": "enable_backups"} request := &ActionRequest{"type": "enable_backups"}
return s.doAction(id, request) return s.doAction(id, request)
} }
// EnableBackups enables backups for a droplet by Tag // EnableBackupsByTag enables backups for Droplets matched by a Tag.
func (s *DropletActionsServiceOp) EnableBackupsByTag(tag string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) EnableBackupsByTag(tag string) (*Action, *Response, error) {
request := &ActionRequest{"type": "enable_backups"} request := &ActionRequest{"type": "enable_backups"}
return s.doActionByTag(tag, request) return s.doActionByTag(tag, request)
} }
// DisableBackups disables 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)
} }
// DisableBackups disables backups for a droplet by tag // DisableBackupsByTag disables backups for Droplet matched by a Tag.
func (s *DropletActionsServiceOp) DisableBackupsByTag(tag string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) DisableBackupsByTag(tag string) (*Action, *Response, error) {
request := &ActionRequest{"type": "disable_backups"} request := &ActionRequest{"type": "disable_backups"}
return s.doActionByTag(tag, request) return s.doActionByTag(tag, request)
} }
// PasswordReset resets the 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)
} }
// RebuildByImageID rebuilds a droplet droplet from an image with a given id. // RebuildByImageID rebuilds a 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)
} }
// RebuildByImageSlug rebuilds a droplet from an image with a given slug. // RebuildByImageSlug rebuilds a Droplet from an Image matched by 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)
} }
// ChangeKernel changes the kernel for a droplet. // 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)
} }
// EnableIPv6 enables IPv6 for 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)
} }
// EnableIPv6 enables IPv6 for a droplet by Tag // EnableIPv6ByTag enables IPv6 for Droplets matched by a Tag.
func (s *DropletActionsServiceOp) EnableIPv6ByTag(tag string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) EnableIPv6ByTag(tag string) (*Action, *Response, error) {
request := &ActionRequest{"type": "enable_ipv6"} request := &ActionRequest{"type": "enable_ipv6"}
return s.doActionByTag(tag, request) return s.doActionByTag(tag, request)
} }
// EnablePrivateNetworking enables private networking for 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)
} }
// EnablePrivateNetworking enables private networking for a droplet by Tag // EnablePrivateNetworkingByTag enables private networking for Droplets matched by a Tag.
func (s *DropletActionsServiceOp) EnablePrivateNetworkingByTag(tag string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) EnablePrivateNetworkingByTag(tag string) (*Action, *Response, error) {
request := &ActionRequest{"type": "enable_private_networking"} request := &ActionRequest{"type": "enable_private_networking"}
return s.doActionByTag(tag, request) return s.doActionByTag(tag, 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)
@ -284,7 +284,7 @@ func (s *DropletActionsServiceOp) doActionByTag(tag string, request *ActionReque
return root.Event, resp, err return root.Event, resp, err
} }
// Get an action for a particular droplet by id. // Get an action for a particular Droplet by id.
func (s *DropletActionsServiceOp) Get(dropletID, actionID int) (*Action, *Response, error) { func (s *DropletActionsServiceOp) Get(dropletID, actionID int) (*Action, *Response, error) {
if dropletID < 1 { if dropletID < 1 {
return nil, nil, NewArgError("dropletID", "cannot be less than 1") return nil, nil, NewArgError("dropletID", "cannot be less than 1")
@ -298,7 +298,7 @@ func (s *DropletActionsServiceOp) Get(dropletID, actionID int) (*Action, *Respon
return s.get(path) return s.get(path)
} }
// GetByURI gets an action for a particular droplet by id. // GetByURI gets an action for a particular Droplet by id.
func (s *DropletActionsServiceOp) GetByURI(rawurl string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) GetByURI(rawurl string) (*Action, *Response, error) {
u, err := url.Parse(rawurl) u, err := url.Parse(rawurl)
if err != nil { if err != nil {

View File

@ -10,7 +10,7 @@ const dropletBasePath = "v2/droplets"
var errNoNetworks = errors.New("no networks have been defined") var errNoNetworks = errors.New("no networks have been defined")
// DropletsService is an interface for interfacing with the droplet // DropletsService is an interface for interfacing with the Droplet
// endpoints of the DigitalOcean API // endpoints of the DigitalOcean API
// See: https://developers.digitalocean.com/documentation/v2#droplets // See: https://developers.digitalocean.com/documentation/v2#droplets
type DropletsService interface { type DropletsService interface {
@ -28,7 +28,7 @@ type DropletsService interface {
Neighbors(int) ([]Droplet, *Response, error) Neighbors(int) ([]Droplet, *Response, error)
} }
// DropletsServiceOp handles communication with the droplet related methods of the // DropletsServiceOp handles communication with the Droplet related methods of the
// DigitalOcean API. // DigitalOcean API.
type DropletsServiceOp struct { type DropletsServiceOp struct {
client *Client client *Client
@ -194,7 +194,7 @@ func (d DropletCreateSSHKey) MarshalJSON() ([]byte, error) {
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.
type DropletCreateRequest struct { type DropletCreateRequest struct {
Name string `json:"name"` Name string `json:"name"`
Region string `json:"region"` Region string `json:"region"`
@ -209,7 +209,7 @@ type DropletCreateRequest struct {
Tags []string `json:"tags"` Tags []string `json:"tags"`
} }
// DropletMultiCreateRequest is a request to create multiple droplets. // DropletMultiCreateRequest is a request to create multiple Droplets.
type DropletMultiCreateRequest struct { type DropletMultiCreateRequest struct {
Names []string `json:"names"` Names []string `json:"names"`
Region string `json:"region"` Region string `json:"region"`
@ -231,13 +231,13 @@ func (d DropletMultiCreateRequest) String() string {
return Stringify(d) return Stringify(d)
} }
// Networks represents the droplet's networks // Networks represents the Droplet's Networks.
type Networks struct { type Networks struct {
V4 []NetworkV4 `json:"v4,omitempty"` V4 []NetworkV4 `json:"v4,omitempty"`
V6 []NetworkV6 `json:"v6,omitempty"` V6 []NetworkV6 `json:"v6,omitempty"`
} }
// NetworkV4 represents a DigitalOcean IPv4 Network // NetworkV4 represents a DigitalOcean IPv4 Network.
type NetworkV4 struct { type NetworkV4 struct {
IPAddress string `json:"ip_address,omitempty"` IPAddress string `json:"ip_address,omitempty"`
Netmask string `json:"netmask,omitempty"` Netmask string `json:"netmask,omitempty"`
@ -261,7 +261,7 @@ func (n NetworkV6) String() string {
return Stringify(n) return Stringify(n)
} }
// Performs a list request given a path // Performs a list request given a path.
func (s *DropletsServiceOp) list(path string) ([]Droplet, *Response, error) { func (s *DropletsServiceOp) list(path string) ([]Droplet, *Response, error) {
req, err := s.client.NewRequest("GET", path, nil) req, err := s.client.NewRequest("GET", path, nil)
if err != nil { if err != nil {
@ -280,7 +280,7 @@ func (s *DropletsServiceOp) list(path string) ([]Droplet, *Response, error) {
return root.Droplets, resp, err return root.Droplets, resp, err
} }
// List all droplets // List all Droplets.
func (s *DropletsServiceOp) List(opt *ListOptions) ([]Droplet, *Response, error) { func (s *DropletsServiceOp) List(opt *ListOptions) ([]Droplet, *Response, error) {
path := dropletBasePath path := dropletBasePath
path, err := addOptions(path, opt) path, err := addOptions(path, opt)
@ -291,7 +291,7 @@ func (s *DropletsServiceOp) List(opt *ListOptions) ([]Droplet, *Response, error)
return s.list(path) return s.list(path)
} }
// List all droplets by tag // ListByTag lists all Droplets matched by a Tag.
func (s *DropletsServiceOp) ListByTag(tag string, opt *ListOptions) ([]Droplet, *Response, error) { func (s *DropletsServiceOp) ListByTag(tag string, opt *ListOptions) ([]Droplet, *Response, error) {
path := fmt.Sprintf("%s?tag_name=%s", dropletBasePath, tag) path := fmt.Sprintf("%s?tag_name=%s", dropletBasePath, tag)
path, err := addOptions(path, opt) path, err := addOptions(path, opt)
@ -302,7 +302,7 @@ func (s *DropletsServiceOp) ListByTag(tag string, opt *ListOptions) ([]Droplet,
return s.list(path) return s.list(path)
} }
// Get individual droplet // Get individual Droplet.
func (s *DropletsServiceOp) Get(dropletID int) (*Droplet, *Response, error) { func (s *DropletsServiceOp) Get(dropletID int) (*Droplet, *Response, error) {
if dropletID < 1 { if dropletID < 1 {
return nil, nil, NewArgError("dropletID", "cannot be less than 1") return nil, nil, NewArgError("dropletID", "cannot be less than 1")
@ -324,7 +324,7 @@ func (s *DropletsServiceOp) Get(dropletID int) (*Droplet, *Response, error) {
return root.Droplet, resp, err return root.Droplet, resp, err
} }
// Create droplet // Create Droplet
func (s *DropletsServiceOp) Create(createRequest *DropletCreateRequest) (*Droplet, *Response, error) { func (s *DropletsServiceOp) Create(createRequest *DropletCreateRequest) (*Droplet, *Response, error) {
if createRequest == nil { if createRequest == nil {
return nil, nil, NewArgError("createRequest", "cannot be nil") return nil, nil, NewArgError("createRequest", "cannot be nil")
@ -349,7 +349,7 @@ func (s *DropletsServiceOp) Create(createRequest *DropletCreateRequest) (*Drople
return root.Droplet, resp, err return root.Droplet, resp, err
} }
// CreateMultiple creates multiple droplets. // CreateMultiple creates multiple Droplets.
func (s *DropletsServiceOp) CreateMultiple(createRequest *DropletMultiCreateRequest) ([]Droplet, *Response, error) { func (s *DropletsServiceOp) CreateMultiple(createRequest *DropletMultiCreateRequest) ([]Droplet, *Response, error) {
if createRequest == nil { if createRequest == nil {
return nil, nil, NewArgError("createRequest", "cannot be nil") return nil, nil, NewArgError("createRequest", "cannot be nil")
@ -386,7 +386,7 @@ func (s *DropletsServiceOp) delete(path string) (*Response, error) {
return resp, err return resp, err
} }
// Delete droplet // Delete Droplet.
func (s *DropletsServiceOp) Delete(dropletID int) (*Response, error) { func (s *DropletsServiceOp) Delete(dropletID int) (*Response, error) {
if dropletID < 1 { if dropletID < 1 {
return nil, NewArgError("dropletID", "cannot be less than 1") return nil, NewArgError("dropletID", "cannot be less than 1")
@ -397,7 +397,7 @@ func (s *DropletsServiceOp) Delete(dropletID int) (*Response, error) {
return s.delete(path) return s.delete(path)
} }
// Delete droplets by tag // DeleteByTag deletes Droplets matched by a Tag.
func (s *DropletsServiceOp) DeleteByTag(tag string) (*Response, error) { func (s *DropletsServiceOp) DeleteByTag(tag string) (*Response, error) {
if tag == "" { if tag == "" {
return nil, NewArgError("tag", "cannot be empty") return nil, NewArgError("tag", "cannot be empty")
@ -408,7 +408,7 @@ func (s *DropletsServiceOp) DeleteByTag(tag string) (*Response, error) {
return s.delete(path) return s.delete(path)
} }
// Kernels lists kernels available for a droplet. // 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) {
if dropletID < 1 { if dropletID < 1 {
return nil, nil, NewArgError("dropletID", "cannot be less than 1") return nil, nil, NewArgError("dropletID", "cannot be less than 1")
@ -434,7 +434,7 @@ func (s *DropletsServiceOp) Kernels(dropletID int, opt *ListOptions) ([]Kernel,
return root.Kernels, resp, err return root.Kernels, resp, err
} }
// Actions lists the actions for a droplet. // 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) {
if dropletID < 1 { if dropletID < 1 {
return nil, nil, NewArgError("dropletID", "cannot be less than 1") return nil, nil, NewArgError("dropletID", "cannot be less than 1")
@ -463,7 +463,7 @@ func (s *DropletsServiceOp) Actions(dropletID int, opt *ListOptions) ([]Action,
return root.Actions, resp, err return root.Actions, resp, err
} }
// Backups lists the backups for a droplet. // 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) {
if dropletID < 1 { if dropletID < 1 {
return nil, nil, NewArgError("dropletID", "cannot be less than 1") return nil, nil, NewArgError("dropletID", "cannot be less than 1")
@ -492,7 +492,7 @@ func (s *DropletsServiceOp) Backups(dropletID int, opt *ListOptions) ([]Image, *
return root.Backups, resp, err return root.Backups, resp, err
} }
// Snapshots lists the snapshots available for a droplet. // 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) {
if dropletID < 1 { if dropletID < 1 {
return nil, nil, NewArgError("dropletID", "cannot be less than 1") return nil, nil, NewArgError("dropletID", "cannot be less than 1")
@ -521,7 +521,7 @@ func (s *DropletsServiceOp) Snapshots(dropletID int, opt *ListOptions) ([]Image,
return root.Snapshots, resp, err return root.Snapshots, resp, err
} }
// Neighbors lists the neighbors for a droplet. // 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) {
if dropletID < 1 { if dropletID < 1 {
return nil, nil, NewArgError("dropletID", "cannot be less than 1") return nil, nil, NewArgError("dropletID", "cannot be less than 1")

View File

@ -220,7 +220,7 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Requ
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
if body != nil { if body != nil {
err := json.NewEncoder(buf).Encode(body) err = json.NewEncoder(buf).Encode(body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -312,12 +312,12 @@ func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
if v != nil { if v != nil {
if w, ok := v.(io.Writer); ok { if w, ok := v.(io.Writer); ok {
_, err := io.Copy(w, resp.Body) _, err = io.Copy(w, resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else { } else {
err := json.NewDecoder(resp.Body).Decode(v) err = json.NewDecoder(resp.Body).Decode(v)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -58,11 +58,7 @@ func (l *Links) IsLastPage() bool {
} }
func (p *Pages) isLast() bool { func (p *Pages) isLast() bool {
if p.Last == "" { return p.Last == ""
return true
}
return false
} }
func pageForURL(urlText string) (int, error) { func pageForURL(urlText string) (int, error) {

View File

@ -29,9 +29,9 @@ type regionsRoot struct {
Links *Links `json:"links"` Links *Links `json:"links"`
} }
type regionRoot struct { // type regionRoot struct { // DEADCODE
Region *Region // Region *Region
} // }
func (r Region) String() string { func (r Region) String() string {
return Stringify(r) return Stringify(r)

View File

@ -69,7 +69,7 @@ func (s *SnapshotsServiceOp) ListVolume(opt *ListOptions) ([]Snapshot, *Response
return s.list(opt, &listOpt) return s.list(opt, &listOpt)
} }
// GetByID retrieves an snapshot by id. // Get retrieves an snapshot by id.
func (s *SnapshotsServiceOp) Get(snapshotID string) (*Snapshot, *Response, error) { func (s *SnapshotsServiceOp) Get(snapshotID string) (*Snapshot, *Response, error) {
return s.get(interface{}(snapshotID)) return s.get(interface{}(snapshotID))
} }

View File

@ -21,12 +21,12 @@ type StorageActionsServiceOp struct {
} }
// StorageAttachment represents the attachement of a block storage // StorageAttachment represents the attachement of a block storage
// volume to a specific droplet under the device name. // volume to a specific Droplet under the device name.
type StorageAttachment struct { type StorageAttachment struct {
DropletID int `json:"droplet_id"` DropletID int `json:"droplet_id"`
} }
// Attach a storage volume to a droplet. // Attach a storage volume to a Droplet.
func (s *StorageActionsServiceOp) Attach(volumeID string, dropletID int) (*Action, *Response, error) { func (s *StorageActionsServiceOp) Attach(volumeID string, dropletID int) (*Action, *Response, error) {
request := &ActionRequest{ request := &ActionRequest{
"type": "attach", "type": "attach",
@ -35,7 +35,7 @@ func (s *StorageActionsServiceOp) Attach(volumeID string, dropletID int) (*Actio
return s.doAction(volumeID, request) return s.doAction(volumeID, request)
} }
// Detach a storage volume from a droplet. // Detach a storage volume from a Droplet.
func (s *StorageActionsServiceOp) Detach(volumeID string) (*Action, *Response, error) { func (s *StorageActionsServiceOp) Detach(volumeID string) (*Action, *Response, error) {
request := &ActionRequest{ request := &ActionRequest{
"type": "detach", "type": "detach",
@ -43,7 +43,7 @@ func (s *StorageActionsServiceOp) Detach(volumeID string) (*Action, *Response, e
return s.doAction(volumeID, request) return s.doAction(volumeID, request)
} }
// Detach a storage volume from a droplet by droplet ID. // DetachByDropletID a storage volume from a Droplet by Droplet ID.
func (s *StorageActionsServiceOp) DetachByDropletID(volumeID string, dropletID int) (*Action, *Response, error) { func (s *StorageActionsServiceOp) DetachByDropletID(volumeID string, dropletID int) (*Action, *Response, error) {
request := &ActionRequest{ request := &ActionRequest{
"type": "detach", "type": "detach",

View File

@ -3,6 +3,7 @@ package godo
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"reflect" "reflect"
) )
@ -17,7 +18,7 @@ func Stringify(message interface{}) string {
} }
// stringifyValue was graciously cargoculted from the goprotubuf library // stringifyValue was graciously cargoculted from the goprotubuf library
func stringifyValue(w *bytes.Buffer, val reflect.Value) { func stringifyValue(w io.Writer, val reflect.Value) {
if val.Kind() == reflect.Ptr && val.IsNil() { if val.Kind() == reflect.Ptr && val.IsNil() {
_, _ = w.Write([]byte("<nil>")) _, _ = w.Write([]byte("<nil>"))
return return
@ -29,6 +30,18 @@ func stringifyValue(w *bytes.Buffer, val reflect.Value) {
case reflect.String: case reflect.String:
fmt.Fprintf(w, `"%s"`, v) fmt.Fprintf(w, `"%s"`, v)
case reflect.Slice: case reflect.Slice:
stringifySlice(w, v)
return
case reflect.Struct:
stringifyStruct(w, v)
default:
if v.CanInterface() {
fmt.Fprint(w, v.Interface())
}
}
}
func stringifySlice(w io.Writer, v reflect.Value) {
_, _ = w.Write([]byte{'['}) _, _ = w.Write([]byte{'['})
for i := 0; i < v.Len(); i++ { for i := 0; i < v.Len(); i++ {
if i > 0 { if i > 0 {
@ -39,8 +52,9 @@ func stringifyValue(w *bytes.Buffer, val reflect.Value) {
} }
_, _ = w.Write([]byte{']'}) _, _ = w.Write([]byte{']'})
return }
case reflect.Struct:
func stringifyStruct(w io.Writer, v reflect.Value) {
if v.Type().Name() != "" { if v.Type().Name() != "" {
_, _ = w.Write([]byte(v.Type().String())) _, _ = w.Write([]byte(v.Type().String()))
} }
@ -75,9 +89,4 @@ func stringifyValue(w *bytes.Buffer, val reflect.Value) {
} }
_, _ = w.Write([]byte{'}'}) _, _ = w.Write([]byte{'}'})
default:
if v.CanInterface() {
fmt.Fprint(w, v.Interface())
}
}
} }

View File

@ -30,6 +30,7 @@ var _ TagsService = &TagsServiceOp{}
type ResourceType string type ResourceType string
const ( const (
//DropletResourceType holds the string representing our ResourceType of Droplet.
DropletResourceType ResourceType = "droplet" DropletResourceType ResourceType = "droplet"
) )
@ -56,18 +57,22 @@ type Tag struct {
Resources *TaggedResources `json:"resources,omitempty"` Resources *TaggedResources `json:"resources,omitempty"`
} }
//TagCreateRequest represents the JSON structure of a request of that type.
type TagCreateRequest struct { type TagCreateRequest struct {
Name string `json:"name"` Name string `json:"name"`
} }
//TagUpdateRequest represents the JSON structure of a request of that type.
type TagUpdateRequest struct { type TagUpdateRequest struct {
Name string `json:"name"` Name string `json:"name"`
} }
// TagResourcesRequest represents the JSON structure of a request of that type.
type TagResourcesRequest struct { type TagResourcesRequest struct {
Resources []Resource `json:"resources"` Resources []Resource `json:"resources"`
} }
// UntagResourcesRequest represents the JSON structure of a request of that type.
type UntagResourcesRequest struct { type UntagResourcesRequest struct {
Resources []Resource `json:"resources"` Resources []Resource `json:"resources"`
} }
@ -183,7 +188,7 @@ func (s *TagsServiceOp) Delete(name string) (*Response, error) {
return resp, err return resp, err
} }
// Associate resources with a tag // TagResources associates resources with a given Tag.
func (s *TagsServiceOp) TagResources(name string, tagRequest *TagResourcesRequest) (*Response, error) { func (s *TagsServiceOp) TagResources(name string, tagRequest *TagResourcesRequest) (*Response, error) {
if name == "" { if name == "" {
return nil, NewArgError("name", "cannot be empty") return nil, NewArgError("name", "cannot be empty")
@ -204,7 +209,7 @@ func (s *TagsServiceOp) TagResources(name string, tagRequest *TagResourcesReques
return resp, err return resp, err
} }
// Dissociate resources with a tag // UntagResources dissociates resources with a given Tag.
func (s *TagsServiceOp) UntagResources(name string, untagRequest *UntagResourcesRequest) (*Response, error) { func (s *TagsServiceOp) UntagResources(name string, untagRequest *UntagResourcesRequest) (*Response, error) {
if name == "" { if name == "" {
return nil, NewArgError("name", "cannot be empty") return nil, NewArgError("name", "cannot be empty")

View File

@ -9,7 +9,7 @@ import (
) )
var ( var (
listEmptyJson string = ` listEmptyJSON = `
{ {
"tags": [ "tags": [
], ],
@ -19,7 +19,7 @@ var (
} }
` `
listJson string = ` listJSON = `
{ {
"tags": [ "tags": [
{ {
@ -55,7 +55,7 @@ var (
} }
` `
createJson string = ` createJSON = `
{ {
"tag": { "tag": {
"name": "testing-1", "name": "testing-1",
@ -69,7 +69,7 @@ var (
} }
` `
getJson string = ` getJSON = `
{ {
"tag": { "tag": {
"name": "testing-1", "name": "testing-1",
@ -170,7 +170,7 @@ func TestTags_List(t *testing.T) {
mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
fmt.Fprint(w, listJson) fmt.Fprint(w, listJSON)
}) })
tags, _, err := client.Tags.List(nil) tags, _, err := client.Tags.List(nil)
@ -191,7 +191,7 @@ func TestTags_ListEmpty(t *testing.T) {
mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
fmt.Fprint(w, listEmptyJson) fmt.Fprint(w, listEmptyJSON)
}) })
tags, _, err := client.Tags.List(nil) tags, _, err := client.Tags.List(nil)
@ -211,7 +211,7 @@ func TestTags_ListPaging(t *testing.T) {
mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
fmt.Fprint(w, listJson) fmt.Fprint(w, listJSON)
}) })
_, resp, err := client.Tags.List(nil) _, resp, err := client.Tags.List(nil)
@ -227,7 +227,7 @@ func TestTags_Get(t *testing.T) {
mux.HandleFunc("/v2/tags/testing-1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/tags/testing-1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
fmt.Fprint(w, getJson) fmt.Fprint(w, getJSON)
}) })
tag, _, err := client.Tags.Get("testing-1") tag, _, err := client.Tags.Get("testing-1")
@ -268,7 +268,7 @@ func TestTags_Create(t *testing.T) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest) t.Errorf("Request body = %+v, expected %+v", v, createRequest)
} }
fmt.Fprintf(w, createJson) fmt.Fprintf(w, createJSON)
}) })
tag, _, err := client.Tags.Create(createRequest) tag, _, err := client.Tags.Create(createRequest)

View File

@ -88,6 +88,9 @@ func TestTimstamp_MarshalReflexivity(t *testing.T) {
} }
var got Timestamp var got Timestamp
err = json.Unmarshal(data, &got) err = json.Unmarshal(data, &got)
if err != nil {
t.Errorf("%s: Unmarshal err=%v", data, err)
}
if !got.Equal(tc.data) { if !got.Equal(tc.data) {
t.Errorf("%s: %+v != %+v", tc.desc, got, data) t.Errorf("%s: %+v != %+v", tc.desc, got, data)
} }
@ -169,6 +172,9 @@ func TestWrappedTimestamp_MarshalReflexivity(t *testing.T) {
} }
var got WrappedTimestamp var got WrappedTimestamp
err = json.Unmarshal(bytes, &got) err = json.Unmarshal(bytes, &got)
if err != nil {
t.Errorf("%s: Unmarshal err=%v", bytes, err)
}
if !got.Time.Equal(tc.data.Time) { if !got.Time.Equal(tc.data.Time) {
t.Errorf("%s: %+v != %+v", tc.desc, got, tc.data) t.Errorf("%s: %+v != %+v", tc.desc, got, tc.data)
} }