From f5489b8e229260817fdabcfb1b930bc38dba9337 Mon Sep 17 00:00:00 2001 From: silenceper Date: Wed, 16 Sep 2020 18:18:24 +0800 Subject: [PATCH] enable gofmt,golint and fix lint errors (#1159) * enable gofmt,golint and fix lint errors Signed-off-by: silenceper * fix Makefile: change to golangci Signed-off-by: silenceper --- .golangci.yml | 4 ++-- Makefile | 13 +++++-------- pkg/scalers/artemis_scaler.go | 8 ++++---- pkg/scalers/azure/azure_monitor_test.go | 18 +++++++++--------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4c4a9ebb082..14d0a9b8dfe 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,9 +16,9 @@ linters: - govet - nolintlint - rowserrcheck - #- gofmt + - gofmt + - golint #- interfacer - #- golint #- goimports #- ineffassign #- misspell diff --git a/Makefile b/Makefile index 884ae12d934..52eddc9f64f 100644 --- a/Makefile +++ b/Makefile @@ -199,20 +199,17 @@ pkg/scalers/liiklus/mocks/mock_liiklus.go: pkg/scalers/liiklus/LiiklusService.pb # Run go fmt against code .PHONY: gofmt gofmt: - go fmt ./... + gofmt -l -w -s . # Run go vet against code .PHONY: govet govet: go vet ./... -# Run revive against code -.PHONY: revive -revive: - revive -config revive.toml -formatter friendly \ - -exclude pkg/scalers/liiklus/mocks/mock_liiklus.go \ - -exclude vendor/... \ - ./... +# Run golangci against code +.PHONY: golangci +golangci: + golangci-lint run ################################################## # Clientset # diff --git a/pkg/scalers/artemis_scaler.go b/pkg/scalers/artemis_scaler.go index 60940d659fb..6f766abe600 100644 --- a/pkg/scalers/artemis_scaler.go +++ b/pkg/scalers/artemis_scaler.go @@ -30,7 +30,7 @@ type artemisMetadata struct { brokerAddress string username string password string - restApiTemplate string + restAPITemplate string queueLength int } @@ -70,9 +70,9 @@ func parseArtemisMetadata(resolvedEnv, metadata, authParams map[string]string) ( meta.queueLength = defaultArtemisQueueLength if val, ok := metadata["restApiTemplate"]; ok && val != "" { - meta.restApiTemplate = metadata["restApiTemplate"] + meta.restAPITemplate = metadata["restApiTemplate"] } else { - meta.restApiTemplate = defaultRestAPITemplate + meta.restAPITemplate = defaultRestAPITemplate } if metadata["managementEndpoint"] == "" { @@ -156,7 +156,7 @@ func (s *artemisScaler) getMonitoringEndpoint() string { "<>", s.metadata.brokerName, "<>", s.metadata.brokerAddress) - monitoringEndpoint := replacer.Replace(s.metadata.restApiTemplate) + monitoringEndpoint := replacer.Replace(s.metadata.restAPITemplate) return monitoringEndpoint } diff --git a/pkg/scalers/azure/azure_monitor_test.go b/pkg/scalers/azure/azure_monitor_test.go index cf0fbb4d957..7b1279683ef 100644 --- a/pkg/scalers/azure/azure_monitor_test.go +++ b/pkg/scalers/azure/azure_monitor_test.go @@ -16,15 +16,15 @@ type testExtractAzMonitorTestData struct { var testExtractAzMonitordata = []testExtractAzMonitorTestData{ {"nothing returned", true, -1, azureExternalMetricRequest{}, insights.Response{Value: &[]insights.Metric{}}}, - {"timeseries null", true, -1, azureExternalMetricRequest{}, insights.Response{Value: &[]insights.Metric{insights.Metric{Timeseries: nil}}}}, - {"timeseries empty", true, -1, azureExternalMetricRequest{}, insights.Response{Value: &[]insights.Metric{insights.Metric{Timeseries: &[]insights.TimeSeriesElement{}}}}}, - {"data nil", true, -1, azureExternalMetricRequest{}, insights.Response{Value: &[]insights.Metric{insights.Metric{Timeseries: &[]insights.TimeSeriesElement{insights.TimeSeriesElement{Data: nil}}}}}}, - {"data empty", true, -1, azureExternalMetricRequest{}, insights.Response{Value: &[]insights.Metric{insights.Metric{Timeseries: &[]insights.TimeSeriesElement{insights.TimeSeriesElement{Data: &[]insights.MetricValue{}}}}}}}, - {"Total Aggregation requested", false, 40, azureExternalMetricRequest{Aggregation: "Total"}, insights.Response{Value: &[]insights.Metric{insights.Metric{Timeseries: &[]insights.TimeSeriesElement{insights.TimeSeriesElement{Data: &[]insights.MetricValue{insights.MetricValue{Total: returnFloat64Ptr(40)}}}}}}}}, - {"Average Aggregation requested", false, 41, azureExternalMetricRequest{Aggregation: "Average"}, insights.Response{Value: &[]insights.Metric{insights.Metric{Timeseries: &[]insights.TimeSeriesElement{insights.TimeSeriesElement{Data: &[]insights.MetricValue{insights.MetricValue{Average: returnFloat64Ptr(41)}}}}}}}}, - {"Maximum Aggregation requested", false, 42, azureExternalMetricRequest{Aggregation: "Maximum"}, insights.Response{Value: &[]insights.Metric{insights.Metric{Timeseries: &[]insights.TimeSeriesElement{insights.TimeSeriesElement{Data: &[]insights.MetricValue{insights.MetricValue{Maximum: returnFloat64Ptr(42)}}}}}}}}, - {"Minimum Aggregation requested", false, 43, azureExternalMetricRequest{Aggregation: "Minimum"}, insights.Response{Value: &[]insights.Metric{insights.Metric{Timeseries: &[]insights.TimeSeriesElement{insights.TimeSeriesElement{Data: &[]insights.MetricValue{insights.MetricValue{Minimum: returnFloat64Ptr(43)}}}}}}}}, - {"Count Aggregation requested", false, 44, azureExternalMetricRequest{Aggregation: "Count"}, insights.Response{Value: &[]insights.Metric{insights.Metric{Timeseries: &[]insights.TimeSeriesElement{insights.TimeSeriesElement{Data: &[]insights.MetricValue{insights.MetricValue{Count: returnFloat64Ptr(44)}}}}}}}}, + {"timeseries null", true, -1, azureExternalMetricRequest{}, insights.Response{Value: &[]insights.Metric{{Timeseries: nil}}}}, + {"timeseries empty", true, -1, azureExternalMetricRequest{}, insights.Response{Value: &[]insights.Metric{{Timeseries: &[]insights.TimeSeriesElement{}}}}}, + {"data nil", true, -1, azureExternalMetricRequest{}, insights.Response{Value: &[]insights.Metric{{Timeseries: &[]insights.TimeSeriesElement{{Data: nil}}}}}}, + {"data empty", true, -1, azureExternalMetricRequest{}, insights.Response{Value: &[]insights.Metric{{Timeseries: &[]insights.TimeSeriesElement{{Data: &[]insights.MetricValue{}}}}}}}, + {"Total Aggregation requested", false, 40, azureExternalMetricRequest{Aggregation: "Total"}, insights.Response{Value: &[]insights.Metric{{Timeseries: &[]insights.TimeSeriesElement{{Data: &[]insights.MetricValue{{Total: returnFloat64Ptr(40)}}}}}}}}, + {"Average Aggregation requested", false, 41, azureExternalMetricRequest{Aggregation: "Average"}, insights.Response{Value: &[]insights.Metric{{Timeseries: &[]insights.TimeSeriesElement{{Data: &[]insights.MetricValue{{Average: returnFloat64Ptr(41)}}}}}}}}, + {"Maximum Aggregation requested", false, 42, azureExternalMetricRequest{Aggregation: "Maximum"}, insights.Response{Value: &[]insights.Metric{{Timeseries: &[]insights.TimeSeriesElement{{Data: &[]insights.MetricValue{{Maximum: returnFloat64Ptr(42)}}}}}}}}, + {"Minimum Aggregation requested", false, 43, azureExternalMetricRequest{Aggregation: "Minimum"}, insights.Response{Value: &[]insights.Metric{{Timeseries: &[]insights.TimeSeriesElement{{Data: &[]insights.MetricValue{{Minimum: returnFloat64Ptr(43)}}}}}}}}, + {"Count Aggregation requested", false, 44, azureExternalMetricRequest{Aggregation: "Count"}, insights.Response{Value: &[]insights.Metric{{Timeseries: &[]insights.TimeSeriesElement{{Data: &[]insights.MetricValue{{Count: returnFloat64Ptr(44)}}}}}}}}, } func returnFloat64Ptr(x float64) *float64 {