From 45e4d06e2e60eb9beffa79fdc8d19c09fbcaed22 Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Sat, 2 Nov 2019 15:03:38 +0100 Subject: [PATCH] Fix wsl issue declarations should never be cuddled See, https://github.com/bombsimon/wsl/blob/master/doc/rules.md#declarations-should-never-be-cuddled Signed-off-by: Mario Trangoni --- collector/collector.go | 5 ++++- collector/lmstat_feature_exp_linux.go | 20 ++++++++++++++------ collector/lmstat_linux.go | 13 +++++++++---- collector/lmstat_linux_test.go | 8 +++++--- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/collector/collector.go b/collector/collector.go index 13248e4..267d2f0 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -124,10 +124,13 @@ func (n FlexlmCollector) Collect(ch chan<- prometheus.Metric) { } func execute(name string, c Collector, ch chan<- prometheus.Metric) { + var ( + success float64 + ) + begin := time.Now() err := c.Update(ch) duration := time.Since(begin) - var success float64 if err != nil { log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err) diff --git a/collector/lmstat_feature_exp_linux.go b/collector/lmstat_feature_exp_linux.go index 69096f8..705593a 100644 --- a/collector/lmstat_feature_exp_linux.go +++ b/collector/lmstat_feature_exp_linux.go @@ -26,9 +26,12 @@ import ( ) func parseLmstatLicenseFeatureExpDate(outStr [][]string) map[int]*featureExp { + var ( + expires float64 + index int + ) + featuresExp := make(map[int]*featureExp) - var expires float64 - var index int // iterate over output lines for _, line := range outStr { lineJoined := strings.Join(line, "") @@ -72,8 +75,10 @@ func parseLmstatLicenseFeatureExpDate(outStr [][]string) map[int]*featureExp { // getLmstatFeatureExpDate returns lmstat active and inactive licenses expiration date func (c *lmstatFeatureExpCollector) getLmstatFeatureExpDate(ch chan<- prometheus.Metric) error { - var outBytes []byte - var err error + var ( + outBytes []byte + err error + ) for _, licenses := range LicenseConfig.Licenses { // Call lmstat with -i (lmstat -i does not give information from the server, @@ -101,8 +106,11 @@ func (c *lmstatFeatureExpCollector) getLmstatFeatureExpDate(ch chan<- prometheus } // features - var featuresToExclude = []string{} - var featuresToInclude = []string{} + var ( + featuresToExclude = []string{} + featuresToInclude = []string{} + ) + if licenses.FeaturesToExclude != "" && licenses.FeaturesToInclude != "" { log.Fatalln("%v: can not define `features_to_include` and "+ "`features_to_exclude` at the same time", licenses.Name) diff --git a/collector/lmstat_linux.go b/collector/lmstat_linux.go index b3a0736..f0d2dc0 100644 --- a/collector/lmstat_linux.go +++ b/collector/lmstat_linux.go @@ -253,8 +253,10 @@ func (c *lmstatCollector) getLmstatInfo(ch chan<- prometheus.Metric) error { // getLmstatLicensesInfo returns lmstat active licenses information func (c *lmstatCollector) getLmstatLicensesInfo(ch chan<- prometheus.Metric) error { - var outBytes []byte - var err error + var ( + outBytes []byte + err error + ) for _, licenses := range LicenseConfig.Licenses { // Call lmstat with -a (display everything) @@ -304,8 +306,11 @@ func (c *lmstatCollector) getLmstatLicensesInfo(ch chan<- prometheus.Metric) err } } // features - var featuresToExclude = []string{} - var featuresToInclude = []string{} + var ( + featuresToExclude = []string{} + featuresToInclude = []string{} + ) + if licenses.FeaturesToExclude != "" && licenses.FeaturesToInclude != "" { log.Fatalln("%v: can not define `features_to_include` and "+ "`features_to_exclude` at the same time", licenses.Name) diff --git a/collector/lmstat_linux_test.go b/collector/lmstat_linux_test.go index 3aba4d6..892e183 100644 --- a/collector/lmstat_linux_test.go +++ b/collector/lmstat_linux_test.go @@ -256,9 +256,11 @@ func TestParseLmstatLicenseInfoFeature(t *testing.T) { t.Fatalf("Couldn't parse user \"cmfy211\" from feature31") } - var found = false - var foundJohnDoe = false - var foundJaneDoe = false + var ( + found = false + foundJohnDoe = false + foundJaneDoe = false + ) for username, licused := range licUsersByFeature["feature100"] { if username == "user13" {