From 949bf60cd2a78da8f7f28cfc8bf2e07cf1ef4248 Mon Sep 17 00:00:00 2001 From: Chris Bartlett Date: Wed, 3 Jul 2019 14:34:29 -0600 Subject: [PATCH] cleaning up --- client.go | 4 ++-- request.go | 2 +- snitch.go | 3 +++ snitch_test.go | 7 +------ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/client.go b/client.go index bad6a29..8123c82 100644 --- a/client.go +++ b/client.go @@ -18,12 +18,12 @@ type Client struct { } // NewClient creates a new API client -func NewClient(apiKey string) (*Client, error) { +func NewClient(apiKey string) *Client { client := &Client{ httpClient: &http.Client{}, apiBaseURL: fmt.Sprintf("%s/%s", apiEndpoint, apiVersion), apiKey: apiKey, } - return client, nil + return client } diff --git a/request.go b/request.go index 52eba77..d8b4321 100644 --- a/request.go +++ b/request.go @@ -15,7 +15,7 @@ type ErrorResponse struct { Validations []Validation `json:"validations"` } -// Validation contains the detials of a API field validation error +// Validation contains the details of a API field validation error type Validation struct { Attribute string `json:"attribute"` Message string `json:"message"` diff --git a/snitch.go b/snitch.go index b617c3d..6ddd7e8 100644 --- a/snitch.go +++ b/snitch.go @@ -79,6 +79,9 @@ func (c *Client) CheckIn(token string) error { } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return fmt.Errorf("Error reading the API check-in response: %v", err) + } if resp.StatusCode == http.StatusAccepted { return nil diff --git a/snitch_test.go b/snitch_test.go index 67b458b..b569ae2 100644 --- a/snitch_test.go +++ b/snitch_test.go @@ -19,16 +19,11 @@ var updatedSnitch deadmanssnitch.Snitch var updatedTags []string func init() { - var err error - flag.StringVar(&apiKey, "apikey", "", "Dead Man's Snitch API key") flag.IntVar(&wait, "wait", 0, "Number of seconds to sleep before deleting snitch (so it can be manually verified)") flag.Parse() - dmsClient, err = deadmanssnitch.NewClient(apiKey) - if err != nil { - panic(err) - } + dmsClient = deadmanssnitch.NewClient(apiKey) rand.Seed(time.Now().UTC().UnixNano()) randomTag = RandomString(10)