Skip to content

Commit

Permalink
address golangci-lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
displague committed Apr 16, 2019
1 parent 6538c24 commit d429c01
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func coupleAPIErrors(r *resty.Response, err error) (*resty.Response, error) {
}

func (e APIError) Error() string {
var x []string
x := []string{}
for _, msg := range e.Errors {
x = append(x, msg.Error())
}
Expand Down
22 changes: 11 additions & 11 deletions pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type ListOptions struct {

// NewListOptions simplified construction of ListOptions using only
// the two writable properties, Page and Filter
func NewListOptions(Page int, Filter string) *ListOptions {
return &ListOptions{PageOptions: &PageOptions{Page: Page}, Filter: Filter}
func NewListOptions(page int, filter string) *ListOptions {
return &ListOptions{PageOptions: &PageOptions{Page: page}, Filter: filter}

}

Expand Down Expand Up @@ -102,7 +102,7 @@ func (c *Client) listHelper(ctx context.Context, i interface{}, opts *ListOption
if r, err = coupleAPIErrors(req.SetResult(DomainsPagedResponse{}).Get(v.endpoint(c))); err == nil {
response, ok := r.Result().(*DomainsPagedResponse)
if !ok {
return fmt.Errorf("Response is not a *DomainsPagedResponse")
return fmt.Errorf("response is not a *DomainsPagedResponse")
}
pages = response.Pages
results = response.Results
Expand Down Expand Up @@ -149,7 +149,7 @@ func (c *Client) listHelper(ctx context.Context, i interface{}, opts *ListOption
if r, err = coupleAPIErrors(req.SetResult(SSHKeysPagedResponse{}).Get(v.endpoint(c))); err == nil {
response, ok := r.Result().(*SSHKeysPagedResponse)
if !ok {
return fmt.Errorf("Response is not a *SSHKeysPagedResponse")
return fmt.Errorf("response is not a *SSHKeysPagedResponse")
}
pages = response.Pages
results = response.Results
Expand Down Expand Up @@ -278,7 +278,7 @@ func (c *Client) listHelper(ctx context.Context, i interface{}, opts *ListOption
}

if opts == nil {
for page := 2; page <= pages; page = page + 1 {
for page := 2; page <= pages; page++ {
if err := c.listHelper(ctx, i, &ListOptions{PageOptions: &PageOptions{Page: page}}); err != nil {
return err
}
Expand All @@ -289,7 +289,7 @@ func (c *Client) listHelper(ctx context.Context, i interface{}, opts *ListOption
}

if opts.Page == 0 {
for page := 2; page <= pages; page = page + 1 {
for page := 2; page <= pages; page++ {
opts.Page = page
if err := c.listHelper(ctx, i, opts); err != nil {
return err
Expand Down Expand Up @@ -336,7 +336,7 @@ func (c *Client) listHelperWithID(ctx context.Context, i interface{}, id int, op
if r, err = coupleAPIErrors(req.SetResult(DomainRecordsPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil {
response, ok := r.Result().(*DomainRecordsPagedResponse)
if !ok {
return fmt.Errorf("Response is not a *DomainRecordsPagedResponse")
return fmt.Errorf("response is not a *DomainRecordsPagedResponse")
}
pages = response.Pages
results = response.Results
Expand Down Expand Up @@ -393,7 +393,7 @@ func (c *Client) listHelperWithID(ctx context.Context, i interface{}, id int, op
}

if opts == nil {
for page := 2; page <= pages; page = page + 1 {
for page := 2; page <= pages; page++ {
if err := c.listHelperWithID(ctx, i, id, &ListOptions{PageOptions: &PageOptions{Page: page}}); err != nil {
return err
}
Expand All @@ -403,7 +403,7 @@ func (c *Client) listHelperWithID(ctx context.Context, i interface{}, id int, op
opts.PageOptions = &PageOptions{}
}
if opts.Page == 0 {
for page := 2; page <= pages; page = page + 1 {
for page := 2; page <= pages; page++ {
opts.Page = page
if err := c.listHelperWithID(ctx, i, id, opts); err != nil {
return err
Expand Down Expand Up @@ -456,7 +456,7 @@ func (c *Client) listHelperWithTwoIDs(ctx context.Context, i interface{}, firstI
}

if opts == nil {
for page := 2; page <= pages; page = page + 1 {
for page := 2; page <= pages; page++ {
if err := c.listHelper(ctx, i, &ListOptions{PageOptions: &PageOptions{Page: page}}); err != nil {
return err
}
Expand All @@ -466,7 +466,7 @@ func (c *Client) listHelperWithTwoIDs(ctx context.Context, i interface{}, firstI
opts.PageOptions = &PageOptions{}
}
if opts.Page == 0 {
for page := 2; page <= pages; page = page + 1 {
for page := 2; page <= pages; page++ {
opts.Page = page
if err := c.listHelperWithTwoIDs(ctx, i, firstID, secondID, opts); err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,15 @@ func (r Resource) render(data ...interface{}) (string, error) {
buf := bytes.NewBufferString(out)

var substitutions interface{}
if len(data) == 1 {
switch len(data) {
case 1:
substitutions = struct{ ID interface{} }{data[0]}
} else if len(data) == 2 {
case 2:
substitutions = struct {
ID interface{}
SecondID interface{}
}{data[0], data[1]}
} else {
default:
return "", NewError("Too many arguments to render template (expected 1 or 2)")
}
if err := r.endpointTemplate.Execute(buf, substitutions); err != nil {
Expand Down
27 changes: 15 additions & 12 deletions waitfor.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ func (client Client) WaitForVolumeLinodeID(ctx context.Context, volumeID int, li
return volume, err
}

if linodeID == nil && volume.LinodeID == nil {
switch {
case linodeID == nil && volume.LinodeID == nil:
return volume, nil
} else if linodeID == nil || volume.LinodeID == nil {
case linodeID == nil || volume.LinodeID == nil:
// continue waiting
} else if *volume.LinodeID == *linodeID {
case *volume.LinodeID == *linodeID:
return volume, nil
}

Expand Down Expand Up @@ -176,6 +177,7 @@ func (client Client) WaitForEventFinished(ctx context.Context, id interface{}, e

// If there are events for this instance + action, inspect them
for _, event := range events {
event := event
if event.Action != action {
// log.Println("action mismatch", event.Action, action)
continue
Expand All @@ -187,21 +189,21 @@ func (client Client) WaitForEventFinished(ctx context.Context, id interface{}, e

var entID string

switch event.Entity.ID.(type) {
switch id := event.Entity.ID.(type) {
case float64, float32:
entID = fmt.Sprintf("%.f", event.Entity.ID)
entID = fmt.Sprintf("%.f", id)
case int:
entID = strconv.Itoa(event.Entity.ID.(int))
entID = strconv.Itoa(id)
default:
entID = fmt.Sprintf("%v", event.Entity.ID)
entID = fmt.Sprintf("%v", id)
}

var findID string
switch id.(type) {
switch id := id.(type) {
case float64, float32:
findID = fmt.Sprintf("%.f", id)
case int:
findID = strconv.Itoa(id.(int))
findID = strconv.Itoa(id)
default:
findID = fmt.Sprintf("%v", id)
}
Expand All @@ -222,11 +224,12 @@ func (client Client) WaitForEventFinished(ctx context.Context, id interface{}, e

}

if event.Status == EventFailed {
switch event.Status {
case EventFailed:
return &event, fmt.Errorf("%s %v action %s failed", titledEntityType, id, action)
} else if event.Status == EventScheduled {
case EventScheduled:
log.Printf("[INFO] %s %v action %s is scheduled", titledEntityType, id, action)
} else if event.Status == EventFinished {
case EventFinished:
log.Printf("[INFO] %s %v action %s is finished", titledEntityType, id, action)
return &event, nil
}
Expand Down

0 comments on commit d429c01

Please sign in to comment.