diff --git a/client.go b/client.go index acfefd1..4fad870 100644 --- a/client.go +++ b/client.go @@ -113,7 +113,7 @@ func NewAdvancedClientForTesting(responses map[string]map[string]string) (*Clien } } - if responseSent == false { + if !responseSent { fmt.Println("Failed to find a matching request!") fmt.Println("Request body:", string(body)) fmt.Println("Method:", req.Method) @@ -139,7 +139,7 @@ func NewClientForTesting(responses map[string]string) (*Client, *httptest.Server } } - if responseSent == false { + if !responseSent { fmt.Println("Failed to find a matching request!") fmt.Println("URL:", req.URL.String()) diff --git a/dns.go b/dns.go index 7aa3a7e..425b1dd 100644 --- a/dns.go +++ b/dns.go @@ -111,7 +111,7 @@ func (c *Client) FindDNSDomain(search string) (*DNSDomain, error) { exactMatch = true result = value } else if strings.Contains(value.Name, search) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/errors.go b/errors.go index 317a8b3..7b52635 100644 --- a/errors.go +++ b/errors.go @@ -290,15 +290,18 @@ func decodeERROR(err error) error { var msg strings.Builder switch err := err.(type) { + case *url.Error: + if _, ok := err.Err.(net.Error); ok { + err := fmt.Errorf("we found a problem connected against the api") + return TimeoutError.wrap(err) + } case net.Error: if err.Timeout() { - err := fmt.Errorf("We have a network issue") + err := fmt.Errorf("we found a network issue") return TimeoutError.wrap(err) } - case *url.Error: - fmt.Println("This is a *url.Error") - if err, ok := err.Err.(net.Error); ok && err.Timeout() { - err := fmt.Errorf("We have a network issue") + if _, ok := err.(*net.DNSError); ok { + err := fmt.Errorf("we found a dns issue") return TimeoutError.wrap(err) } case wrapError: @@ -308,19 +311,19 @@ func decodeERROR(err error) error { byt := []byte(errorData.Reason) if err := json.Unmarshal(byt, &dat); err != nil { - err := errors.New("Failed to decode the response expected from the API") + err := errors.New("failed to decode the response expected from the API") return ResponseDecodeFailedError.wrap(err) } if _, ok := dat["status"].(float64); ok { if dat["status"].(float64) == 500 { - err := errors.New("Internal Server Error") + err := errors.New("internal Server Error") return InternalServerError.wrap(err) } } if dat["result"] == "requires_authentication" { - err := errors.New("Authentication Error") + err := errors.New("authentication Error") return AuthenticationError.wrap(err) } diff --git a/firewall.go b/firewall.go index 1bf7582..41f884b 100644 --- a/firewall.go +++ b/firewall.go @@ -86,7 +86,7 @@ func (c *Client) FindFirewall(search string) (*Firewall, error) { exactMatch = true result = value } else if strings.Contains(value.Name, search) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/instance.go b/instance.go index 5e814b5..2215ea2 100644 --- a/instance.go +++ b/instance.go @@ -123,7 +123,7 @@ func (c *Client) FindInstance(search string) (*Instance, error) { exactMatch = true result = value } else if strings.Contains(value.Hostname, search) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/instance_size.go b/instance_size.go index 78a8be1..b7836ef 100644 --- a/instance_size.go +++ b/instance_size.go @@ -50,7 +50,7 @@ func (c *Client) FindInstanceSizes(search string) (*InstanceSize, error) { exactMatch = true result = value } else if strings.Contains(value.Name, search) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/instance_test.go b/instance_test.go index b317f0a..5457f55 100644 --- a/instance_test.go +++ b/instance_test.go @@ -5,7 +5,7 @@ import ( ) func TestListInstances(t *testing.T) { - client, server, err := NewClientForTesting(map[string]string{ + client, server, _ := NewClientForTesting(map[string]string{ "/v2/instances": `{"page": 1, "per_page": 20, "pages": 2, "items":[{"id": "12345", "hostname": "foo.example.com"}]}`, }) defer server.Close() diff --git a/kubernetes.go b/kubernetes.go index ea6abc9..7490142 100644 --- a/kubernetes.go +++ b/kubernetes.go @@ -157,7 +157,7 @@ func (c *Client) FindKubernetesCluster(search string) (*KubernetesCluster, error exactMatch = true result = value } else if strings.Contains(strings.ToUpper(value.Name), strings.ToUpper(search)) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/kubernetes_test.go b/kubernetes_test.go index bf18ff0..f2294e4 100644 --- a/kubernetes_test.go +++ b/kubernetes_test.go @@ -125,7 +125,7 @@ func TestFindKubernetesCluster(t *testing.T) { }) defer server.Close() - got, err := client.FindKubernetesCluster("69a23478") + got, _ := client.FindKubernetesCluster("69a23478") if got.ID != "69a23478-a89e-41d2-97b1-6f4c341cee70" { t.Errorf("Expected %s, got %s", "69a23478-a89e-41d2-97b1-6f4c341cee70", got.ID) } @@ -150,7 +150,7 @@ func TestFindKubernetesCluster(t *testing.T) { t.Errorf("Expected %s, got %s", "d1cd0b71-5da1-492e-9d0d-a46ccdaae2fa", got.ID) } - _, err = client.FindKubernetesCluster("cluster") + _, err := client.FindKubernetesCluster("cluster") if err.Error() != "MultipleMatchesError: unable to find cluster because there were multiple matches" { t.Errorf("Expected %s, got %s", "unable to find cluster because there were multiple matches", err.Error()) } diff --git a/loadbalancer.go b/loadbalancer.go index 1fb5114..685a70e 100644 --- a/loadbalancer.go +++ b/loadbalancer.go @@ -87,7 +87,7 @@ func (c *Client) FindLoadBalancer(search string) (*LoadBalancer, error) { exactMatch = true result = value } else if strings.Contains(value.Hostname, search) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/loadbalancer_test.go b/loadbalancer_test.go index f0dfd39..9035d14 100644 --- a/loadbalancer_test.go +++ b/loadbalancer_test.go @@ -67,7 +67,7 @@ func TestFindLoadBalancer(t *testing.T) { }) defer server.Close() - got, err := client.FindLoadBalancer("542e9eca") + got, _ := client.FindLoadBalancer("542e9eca") if got.ID != "542e9eca-539d-45e6-b629-2f905d0b5f93" { t.Errorf("Expected %s, got %s", "542e9eca-539d-45e6-b629-2f905d0b5f93", got.ID) } @@ -87,7 +87,7 @@ func TestFindLoadBalancer(t *testing.T) { t.Errorf("Expected %s, got %s", "c33051ae-f337-45de-a3a5-004d822deff5", got.ID) } - _, err = client.FindLoadBalancer("example") + _, err := client.FindLoadBalancer("example") if err.Error() != "MultipleMatchesError: unable to find example because there were multiple matches" { t.Errorf("Expected %s, got %s", "unable to find example because there were multiple matches", err.Error()) } diff --git a/network.go b/network.go index 8020b77..857341d 100644 --- a/network.go +++ b/network.go @@ -37,14 +37,14 @@ func (c *Client) GetDefaultNetwork() (*Network, error) { } networks := make([]Network, 0) - err = json.NewDecoder(bytes.NewReader(resp)).Decode(&networks) + json.NewDecoder(bytes.NewReader(resp)).Decode(&networks) for _, network := range networks { if network.Default { return &network, nil } } - return nil, errors.New("No default network found") + return nil, errors.New("no default network found") } // NewNetwork creates a new private network @@ -94,7 +94,7 @@ func (c *Client) FindNetwork(search string) (*Network, error) { exactMatch = true result = value } else if strings.Contains(value.Name, search) || strings.Contains(value.ID, search) || strings.Contains(value.Label, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/network_test.go b/network_test.go index c0da6b2..6749f59 100644 --- a/network_test.go +++ b/network_test.go @@ -94,7 +94,7 @@ func TestFindNetwork(t *testing.T) { }) defer server.Close() - got, err := client.FindNetwork("34") + got, _ := client.FindNetwork("34") if got.ID != "12345" { t.Errorf("Expected %s, got %s", "12345", got.ID) } @@ -114,12 +114,12 @@ func TestFindNetwork(t *testing.T) { t.Errorf("Expected %s, got %s", "67890", got.ID) } - got, err = client.FindNetwork("production") + got, _ = client.FindNetwork("production") if got.ID != "67890" { t.Errorf("Expected %s, got %s", "67890", got.ID) } - _, err = client.FindNetwork("net") + _, err := client.FindNetwork("net") if err.Error() != "MultipleMatchesError: unable to find net because there were multiple matches" { t.Errorf("Expected %s, got %s", "unable to find net because there were multiple matches", err.Error()) } diff --git a/region.go b/region.go index fa0040b..85918ae 100644 --- a/region.go +++ b/region.go @@ -57,7 +57,7 @@ func (c *Client) FindRegion(search string) (*Region, error) { exactMatch = true result = value } else if strings.Contains(value.Name, search) || strings.Contains(value.Code, search) || strings.Contains(value.Country, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } @@ -88,5 +88,5 @@ func (c *Client) GetDefaultRegion() (*Region, error) { } } - return nil, errors.New("No default region found") + return nil, errors.New("no default region found") } diff --git a/snapshot.go b/snapshot.go index 760fb24..48d1362 100644 --- a/snapshot.go +++ b/snapshot.go @@ -78,7 +78,7 @@ func (c *Client) FindSnapshot(search string) (*Snapshot, error) { exactMatch = true result = value } else if strings.Contains(value.Name, search) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/snapshot_test.go b/snapshot_test.go index 6cb53dc..b4540fd 100644 --- a/snapshot_test.go +++ b/snapshot_test.go @@ -131,7 +131,7 @@ func TestFindSnapshot(t *testing.T) { }) defer server.Close() - got, err := client.FindSnapshot("ff39") + got, _ := client.FindSnapshot("ff39") if got.ID != "0ca69adc-ff39-4fc1-8f08-d91434e86fac" { t.Errorf("Expected %s, got %s", "0ca69adc-ff39-4fc1-8f08-d91434e86fac", got.ID) } @@ -151,7 +151,7 @@ func TestFindSnapshot(t *testing.T) { t.Errorf("Expected %s, got %s", "aadec58e-26f4-43e7-8963-18739519ef76", got.ID) } - _, err = client.FindSnapshot("backup") + _, err := client.FindSnapshot("backup") if err.Error() != "MultipleMatchesError: unable to find backup because there were multiple matches" { t.Errorf("Expected %s, got %s", "unable to find backup because there were multiple matches", err.Error()) } diff --git a/ssh_key.go b/ssh_key.go index bcc40a3..ee66bc6 100644 --- a/ssh_key.go +++ b/ssh_key.go @@ -75,7 +75,7 @@ func (c *Client) FindSSHKey(search string) (*SSHKey, error) { exactMatch = true result = value } else if strings.Contains(value.Name, search) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/ssh_key_test.go b/ssh_key_test.go index 04a93e3..b8ae2d6 100644 --- a/ssh_key_test.go +++ b/ssh_key_test.go @@ -51,7 +51,7 @@ func TestFindSSHKey(t *testing.T) { }) defer server.Close() - got, err := client.FindSSHKey("34") + got, _ := client.FindSSHKey("34") if got.ID != "12345" { t.Errorf("Expected %s, got %s", "12345", got.ID) } @@ -61,7 +61,7 @@ func TestFindSSHKey(t *testing.T) { t.Errorf("Expected %s, got %s", "12345", got.ID) } - _, err = client.FindSSHKey("23") + _, err := client.FindSSHKey("23") if err.Error() != "MultipleMatchesError: unable to find 23 because there were multiple matches" { t.Errorf("Expected %s, got %s", "unable to find 23 because there were multiple matches", err.Error()) } diff --git a/template.go b/template.go index dd8fe2e..4c1ea9f 100644 --- a/template.go +++ b/template.go @@ -103,7 +103,7 @@ func (c *Client) FindTemplate(search string) (*Template, error) { exactMatch = true result = value } else if strings.Contains(value.Code, search) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/volume.go b/volume.go index 172b1eb..3f5e83c 100644 --- a/volume.go +++ b/volume.go @@ -67,7 +67,7 @@ func (c *Client) FindVolume(search string) (*Volume, error) { exactMatch = true result = value } else if strings.Contains(value.Name, search) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/volume_test.go b/volume_test.go index 35f659e..31748dc 100644 --- a/volume_test.go +++ b/volume_test.go @@ -55,7 +55,7 @@ func TestFindVolume(t *testing.T) { }) defer server.Close() - got, err := client.FindVolume("34") + got, _ := client.FindVolume("34") if got.ID != "12345" { t.Errorf("Expected %s, got %s", "12345", got.ID) } @@ -75,7 +75,7 @@ func TestFindVolume(t *testing.T) { t.Errorf("Expected %s, got %s", "67890", got.ID) } - _, err = client.FindVolume("volume") + _, err := client.FindVolume("volume") if err.Error() != "MultipleMatchesError: unable to find volume because there were multiple matches" { t.Errorf("Expected %s, got %s", "unable to find volume because there were multiple matches", err.Error()) } diff --git a/webhook.go b/webhook.go index d36e6c0..3f3e4b0 100644 --- a/webhook.go +++ b/webhook.go @@ -71,7 +71,7 @@ func (c *Client) FindWebhook(search string) (*Webhook, error) { exactMatch = true result = value } else if strings.Contains(value.URL, search) || strings.Contains(value.ID, search) { - if exactMatch == false { + if !exactMatch { result = value partialMatchesCount++ } diff --git a/webhook_test.go b/webhook_test.go index b1d99b2..0b2ab00 100644 --- a/webhook_test.go +++ b/webhook_test.go @@ -105,7 +105,7 @@ func TestFindWebhook(t *testing.T) { }) defer server.Close() - got, err := client.FindWebhook("34") + got, _ := client.FindWebhook("34") if got.ID != "12345" { t.Errorf("Expected %s, got %s", "12345", got.ID) } @@ -125,7 +125,7 @@ func TestFindWebhook(t *testing.T) { t.Errorf("Expected %s, got %s", "67890", got.ID) } - _, err = client.FindWebhook("example") + _, err := client.FindWebhook("example") if err.Error() != "MultipleMatchesError: unable to find example because there were multiple matches" { t.Errorf("Expected %s, got %s", "unable to find example because there were multiple matches", err.Error()) }