From 1702b8ca8cba7063dd2a3d97fe881bf87e24dde9 Mon Sep 17 00:00:00 2001 From: Justin Kromlinger Date: Wed, 3 Jul 2024 22:00:29 +0200 Subject: [PATCH] chore: go vet --- prometheus.go | 22 +++++++++++----------- varnish.go | 4 ++-- varnish_test.go | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/prometheus.go b/prometheus.go index c54f642..91461ff 100644 --- a/prometheus.go +++ b/prometheus.go @@ -114,25 +114,25 @@ type group struct { var ( groups = []group{ - group{name: "backend", prefixes: []string{ + {name: "backend", prefixes: []string{ "vbe.", }}, - group{name: "mempool", prefixes: []string{ + {name: "mempool", prefixes: []string{ "mempool.", }}, - group{name: "lck", prefixes: []string{ + {name: "lck", prefixes: []string{ "lck.", }}, - group{name: "sma", prefixes: []string{ + {name: "sma", prefixes: []string{ "sma.", }}, - group{name: "smf", prefixes: []string{ + {name: "smf", prefixes: []string{ "smf.", }}, - group{name: "mgt", prefixes: []string{ + {name: "mgt", prefixes: []string{ "mgt.", }}, - group{name: "main", prefixes: []string{ + {name: "main", prefixes: []string{ "main.", }}, } @@ -148,18 +148,18 @@ type grouping struct { var ( fqGroupPrefixes = []*grouping{ - &grouping{ + { prefix: "main_fetch", total: "main_s_fetch", desc: "Number of fetches", }, - &grouping{ + { newPrefix: "main_sessions", prefix: "main_sess", total: "main_s_sess", desc: "Number of sessions", }, - &grouping{ + { newPrefix: "main_worker_threads", prefix: "main_n_wrk", total: "main_n_wrk", @@ -229,7 +229,7 @@ func cleanBackendName(name string) string { if strings.HasPrefix(name, "reload_") { dot := strings.Index(name, ".") if dot != -1 { - name = name[dot + 1:] + name = name[dot+1:] } } diff --git a/varnish.go b/varnish.go index 9d74ba5..8311145 100644 --- a/varnish.go +++ b/varnish.go @@ -125,7 +125,7 @@ func ScrapeVarnishFrom(buf []byte, ch chan<- prometheus.Metric) ([]byte, error) ) flag, _ := stringProperty(data, "flag") - if value, ok := data["description"]; ok && vErr == nil { + if value, ok := data["description"]; ok { if vDescription, ok = value.(string); !ok { vErr = fmt.Errorf("%s description it not a string", vName) } @@ -227,7 +227,7 @@ func executeVarnishstat(varnishstatExe string, params ...string) (*bytes.Buffer, // 'VBE.reload_20191014_091124_78599' as by varnishreload in 6+ func findMostRecentVbeReloadPrefix(countersJSON map[string]interface{}) string { var mostRecentVbeReloadPrefix string - for vName, _ := range countersJSON { + for vName := range countersJSON { // Checking only the required ".happy" stat if strings.HasPrefix(vName, vbeReload) && strings.HasSuffix(vName, ".happy") { dotAfterPrefixIndex := len(vbeReload) + strings.Index(vName[len(vbeReload):], ".") diff --git a/varnish_test.go b/varnish_test.go index 9d6c103..d731444 100644 --- a/varnish_test.go +++ b/varnish_test.go @@ -15,31 +15,31 @@ var testFileVersions = []string{"3.0.5", "4.0.5", "4.1.1", "5.2.0", "6.0.0", "6. func Test_VarnishVersion(t *testing.T) { tests := map[string]*varnishVersion{ - "varnishstat (varnish-6.5.1 revision 1dae23376bb5ea7a6b8e9e4b9ed95cdc9469fb64)": &varnishVersion{ + "varnishstat (varnish-6.5.1 revision 1dae23376bb5ea7a6b8e9e4b9ed95cdc9469fb64)": { Major: 6, Minor: 5, Patch: 1, Revision: "1dae23376bb5ea7a6b8e9e4b9ed95cdc9469fb64", }, - "varnishstat (varnish-6.0.0 revision a068361dff0d25a0d85cf82a6e5fdaf315e06a7d)": &varnishVersion{ + "varnishstat (varnish-6.0.0 revision a068361dff0d25a0d85cf82a6e5fdaf315e06a7d)": { Major: 6, Minor: 0, Patch: 0, Revision: "a068361dff0d25a0d85cf82a6e5fdaf315e06a7d", }, - "varnishstat (varnish-5.2.0 revision 4c4875cbf)": &varnishVersion{ + "varnishstat (varnish-5.2.0 revision 4c4875cbf)": { Major: 5, Minor: 2, Patch: 0, Revision: "4c4875cbf", }, - "varnishstat (varnish-4.1.10 revision 1d090c5a08f41c36562644bafcce9d3cb85d824f)": &varnishVersion{ + "varnishstat (varnish-4.1.10 revision 1d090c5a08f41c36562644bafcce9d3cb85d824f)": { Major: 4, Minor: 1, Patch: 10, Revision: "1d090c5a08f41c36562644bafcce9d3cb85d824f", }, - "varnishstat (varnish-4.1.0 revision 3041728)": &varnishVersion{ + "varnishstat (varnish-4.1.0 revision 3041728)": { Major: 4, Minor: 1, Patch: 0, Revision: "3041728", }, - "varnishstat (varnish-4 revision)": &varnishVersion{ + "varnishstat (varnish-4 revision)": { Major: 4, Minor: -1, Patch: -1, }, - "varnishstat (varnish-3.0.5 revision 1a89b1f)": &varnishVersion{ + "varnishstat (varnish-3.0.5 revision 1a89b1f)": { Major: 3, Minor: 0, Patch: 5, Revision: "1a89b1f", }, - "varnish 2.0": &varnishVersion{ + "varnish 2.0": { Major: 2, Minor: 0, Patch: -1, }, - "varnish 1": &varnishVersion{ + "varnish 1": { Major: 1, Minor: -1, Patch: -1, }, } @@ -114,7 +114,7 @@ func Test_VarnishBackendNames(t *testing.T) { vIdentifier string vErr error ) - if value, ok := data["description"]; ok && vErr == nil { + if value, ok := data["description"]; ok { if vDescription, ok = value.(string); !ok { vErr = fmt.Errorf("%s description it not a string", vName) } @@ -266,7 +266,7 @@ func (tc *testCollector) Describe(ch chan<- *prometheus.Desc) { } func (tc *testCollector) Collect(ch chan<- prometheus.Metric) { - buf, err := ioutil.ReadFile(tc.filepath) + buf, err := os.ReadFile(tc.filepath) if err != nil { tc.t.Fatal(err.Error()) }