From 202fa2cf14bb4a4ab77544ccc43593095857e8a8 Mon Sep 17 00:00:00 2001 From: Trevor Rosen Date: Tue, 14 Jan 2020 10:53:31 -0600 Subject: [PATCH] Clean up linter errors #24 --- appoptics/resource_appoptics_alert.go | 2 +- appoptics/resource_appoptics_metric.go | 12 ++++++------ appoptics/resource_appoptics_service.go | 22 ++++++++++++++-------- appoptics/resource_appoptics_space.go | 12 ++++++++++-- appoptics/resource_librato_space_chart.go | 16 ++++++++++++---- 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/appoptics/resource_appoptics_alert.go b/appoptics/resource_appoptics_alert.go index a33929e..9d4a914 100644 --- a/appoptics/resource_appoptics_alert.go +++ b/appoptics/resource_appoptics_alert.go @@ -297,7 +297,7 @@ func resourceAppOpticsAlertRead(d *schema.ResourceData, meta interface{}) error } log.Printf("[INFO] Received AppOptics Alert: %s", alert.Name) - d.Set("name", alert.Name) + d.Set("name", alert.Name) //nolint if err := d.Set("description", alert.Description); err != nil { return err diff --git a/appoptics/resource_appoptics_metric.go b/appoptics/resource_appoptics_metric.go index b689f5c..abdc198 100644 --- a/appoptics/resource_appoptics_metric.go +++ b/appoptics/resource_appoptics_metric.go @@ -193,23 +193,23 @@ func resourceAppOpticsMetricRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error reading AppOptics Metric %s: %s", id, err) } - d.Set("name", metric.Name) - d.Set("type", metric.Type) + d.Set("name", metric.Name) //nolint + d.Set("type", metric.Type) //nolint if metric.Description != "" { - d.Set("description", metric.Description) + d.Set("description", metric.Description) //nolint } if metric.DisplayName != "" { - d.Set("display_name", metric.DisplayName) + d.Set("display_name", metric.DisplayName) //nolint } if metric.Period != 0 { - d.Set("period", metric.Period) + d.Set("period", metric.Period) //nolint } if metric.Composite != "" { - d.Set("composite", metric.Composite) + d.Set("composite", metric.Composite) //nolint } attributes := metricAttributesGather(d, &metric.Attributes) diff --git a/appoptics/resource_appoptics_service.go b/appoptics/resource_appoptics_service.go index 97d724a..0a32707 100644 --- a/appoptics/resource_appoptics_service.go +++ b/appoptics/resource_appoptics_service.go @@ -45,9 +45,7 @@ func resourceAppOpticsService() *schema.Resource { // Takes JSON in a string. Decodes JSON into // settings hash func resourceAppOpticsServicesExpandSettings(rawSettings string) (map[string]string, error) { - var settings map[string]string - - settings = make(map[string]string) + settings := make(map[string]string) err := json.Unmarshal([]byte(rawSettings), &settings) if err != nil { return nil, fmt.Errorf("Error decoding JSON: %s", err) @@ -103,7 +101,7 @@ func resourceAppOpticsServiceCreate(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("Error creating AppOptics service: %s", err) } - resource.Retry(1*time.Minute, func() *resource.RetryError { + retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError { _, err := client.ServicesService().Retrieve(serviceResult.ID) if err != nil { if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 { @@ -114,6 +112,10 @@ func resourceAppOpticsServiceCreate(d *schema.ResourceData, meta interface{}) er return nil }) + if retryErr != nil { + return retryErr + } + d.SetId(strconv.Itoa(serviceResult.ID)) return resourceAppOpticsServiceReadResult(d, *serviceResult) } @@ -141,10 +143,10 @@ func resourceAppOpticsServiceRead(d *schema.ResourceData, meta interface{}) erro func resourceAppOpticsServiceReadResult(d *schema.ResourceData, service appoptics.Service) error { d.SetId(strconv.FormatUint(uint64(service.ID), 10)) - d.Set("type", service.Type) - d.Set("title", service.Title) + d.Set("type", service.Type) //nolint + d.Set("title", service.Title) //nolint settings, _ := resourceAppOpticsServicesFlatten(service.Settings) - d.Set("settings", settings) + d.Set("settings", settings) //nolint return nil } @@ -223,7 +225,7 @@ func resourceAppOpticsServiceDelete(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("Error deleting Service: %s", err) } - resource.Retry(1*time.Minute, func() *resource.RetryError { + retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError { _, err := client.ServicesService().Retrieve(int(id)) if err != nil { if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 { @@ -234,6 +236,10 @@ func resourceAppOpticsServiceDelete(d *schema.ResourceData, meta interface{}) er return resource.RetryableError(fmt.Errorf("service still exists")) }) + if retryErr != nil { + return retryErr + } + d.SetId("") return nil } diff --git a/appoptics/resource_appoptics_space.go b/appoptics/resource_appoptics_space.go index 3fa00f0..ec13b2c 100644 --- a/appoptics/resource_appoptics_space.go +++ b/appoptics/resource_appoptics_space.go @@ -38,7 +38,7 @@ func resourceAppOpticsSpaceCreate(d *schema.ResourceData, meta interface{}) erro return fmt.Errorf("Error creating AppOptics space %s: %s", name, err) } - resource.Retry(1*time.Minute, func() *resource.RetryError { + retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError { _, err := client.SpacesService().Retrieve(space.ID) if err != nil { if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 { @@ -49,6 +49,10 @@ func resourceAppOpticsSpaceCreate(d *schema.ResourceData, meta interface{}) erro return nil }) + if retryErr != nil { + return retryErr + } + d.SetId(strconv.Itoa(space.ID)) return resourceAppOpticsSpaceReadResult(d, space) } @@ -116,7 +120,7 @@ func resourceAppOpticsSpaceDelete(d *schema.ResourceData, meta interface{}) erro return fmt.Errorf("Error deleting space: %s", err) } - resource.Retry(1*time.Minute, func() *resource.RetryError { + retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError { _, err := client.SpacesService().Retrieve(int(id)) if err != nil { if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 { @@ -127,6 +131,10 @@ func resourceAppOpticsSpaceDelete(d *schema.ResourceData, meta interface{}) erro return resource.RetryableError(fmt.Errorf("space still exists")) }) + if retryErr != nil { + return retryErr + } + d.SetId("") return nil } diff --git a/appoptics/resource_librato_space_chart.go b/appoptics/resource_librato_space_chart.go index 7201207..a31c4dd 100644 --- a/appoptics/resource_librato_space_chart.go +++ b/appoptics/resource_librato_space_chart.go @@ -258,7 +258,7 @@ func resourceAppOpticsSpaceChartCreate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error creating AppOptics space chart %s: %s", spaceChart.Name, err) } - resource.Retry(1*time.Minute, func() *resource.RetryError { + retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError { _, err := client.ChartsService().Retrieve(spaceChartResult.ID, spaceID) if err != nil { if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 { @@ -269,6 +269,10 @@ func resourceAppOpticsSpaceChartCreate(d *schema.ResourceData, meta interface{}) return nil }) + if retryErr != nil { + return retryErr + } + return resourceAppOpticsSpaceChartReadResult(d, spaceChartResult) } @@ -443,10 +447,10 @@ func resourceAppOpticsSpaceChartUpdate(d *schema.ResourceData, meta interface{}) if v, ok := streamData["units_longs"].(string); ok && v != "" { stream.UnitsLong = v } - if v, ok := streamData["min"].(int); ok && !math.IsNaN(float64(v)) { + if v, ok := streamData["min"].(int); ok { stream.Min = v } - if v, ok := streamData["max"].(int); ok && !math.IsNaN(float64(v)) { + if v, ok := streamData["max"].(int); ok { stream.Max = v } streams[i] = stream @@ -503,7 +507,7 @@ func resourceAppOpticsSpaceChartDelete(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error deleting space: %s", err) } - resource.Retry(1*time.Minute, func() *resource.RetryError { + retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError { _, err := client.ChartsService().Retrieve(id, spaceID) if err != nil { if errResp, ok := err.(*appoptics.ErrorResponse); ok && errResp.Response.StatusCode == 404 { @@ -514,6 +518,10 @@ func resourceAppOpticsSpaceChartDelete(d *schema.ResourceData, meta interface{}) return resource.RetryableError(fmt.Errorf("space chart still exists")) }) + if err != nil { + return retryErr + } + d.SetId("") return nil }