@cryptotaxi247 / netdata-1 / commits / 08aae6051

chore(go): go fix (#22173)

Ilya Mashchenko committed Apr 9, 2026 at 18:52 UTC 08aae60515ae9327fe4396fbeda68d8c7e4152a7
37 files changed +23 -57
src/go/plugin/go.d/collector/dnsmasq_dhcp/parse_configuration.go
+2 -2
@@ -108,9 +108,9 @@ func parseDHCPRangeValue(s string) (r string) {
108 s = strings.ReplaceAll(s, " ", "")
109
110 var start, end netip.Addr
111 - parts := strings.Split(s, ",")
111 + parts := strings.SplitSeq(s, ",")
112
113 - for _, v := range parts {
113 + for v := range parts {
114 if !start.IsValid() {
115 start, _ = netip.ParseAddr(v)
116 continue
src/go/plugin/go.d/collector/fail2ban/collect.go
+6 -6
@@ -114,18 +114,18 @@ func parseFail2banJailStatus(jailStatus []byte) (failed, banned int64, err error
114 }
115
116 if !failedFound {
117 - if i := strings.Index(text, failedSub); i != -1 {
117 + if _, after, ok := strings.Cut(text, failedSub); ok {
118 failedFound = true
119 - s := strings.TrimSpace(text[i+len(failedSub):])
119 + s := strings.TrimSpace(after)
120 if failed, err = strconv.ParseInt(s, 10, 64); err != nil {
121 return 0, 0, fmt.Errorf("failed to parse currently failed value (%s): %v", s, err)
122 }
123 }
124 }
125 if !bannedFound {
126 - if i := strings.Index(text, bannedSub); i != -1 {
126 + if _, after, ok := strings.Cut(text, bannedSub); ok {
127 bannedFound = true
128 - s := strings.TrimSpace(text[i+len(bannedSub):])
128 + s := strings.TrimSpace(after)
129 if banned, err = strconv.ParseInt(s, 10, 64); err != nil {
130 return 0, 0, fmt.Errorf("failed to parse currently banned value (%s): %v", s, err)
131 }
@@ -150,8 +150,8 @@ func parseFail2banStatus(status []byte) ([]string, error) {
150 for sc.Scan() {
151 text := strings.TrimSpace(sc.Text())
152
153 - if i := strings.Index(text, sub); i != -1 {
154 - s := strings.ReplaceAll(text[i+len(sub):], ",", "")
153 + if _, after, ok := strings.Cut(text, sub); ok {
154 + s := strings.ReplaceAll(after, ",", "")
155 jails = strings.Fields(s)
156 break
157 }
src/go/plugin/go.d/collector/litespeed/collect.go
+5 -5
@@ -69,16 +69,16 @@ func (c *Collector) collectReport(mx map[string]int64, filename string) error {
69 line = strings.TrimPrefix(line, "REQ_RATE []:")
70 }
71
72 - parts := strings.Split(line, ",")
72 + parts := strings.SplitSeq(line, ",")
73
74 - for _, part := range parts {
75 - i := strings.IndexByte(part, ':')
76 - if i == -1 {
74 + for part := range parts {
75 + before, after, ok := strings.Cut(part, ":")
76 + if !ok {
77 c.Debugf("Skipping metric '%s': missing colon separator", part)
78 continue
79 }
80
81 - metric, sVal := strings.TrimSpace(part[:i]), strings.TrimSpace(part[i+1:])
81 + metric, sVal := strings.TrimSpace(before), strings.TrimSpace(after)
82
83 val, err := strconv.ParseFloat(sVal, 64)
84 if err != nil {
src/go/plugin/go.d/collector/sensors/collector_test.go
+1 -1
@@ -270,7 +270,7 @@ func TestCollector_Collect(t *testing.T) {
270
271 var mx map[string]int64
272
273 - for i := 0; i < 10; i++ {
273 + for range 10 {
274 mx = collr.Collect(context.Background())
275 }
276
src/go/plugin/go.d/collector/systemdunits/collector_test.go
+2 -2
@@ -855,7 +855,7 @@ func TestCollector_Collect(t *testing.T) {
855
856 var mx map[string]int64
857
858 - for i := 0; i < 10; i++ {
858 + for range 10 {
859 mx = collr.Collect(context.Background())
860 }
861
@@ -875,7 +875,7 @@ func TestCollector_connectionReuse(t *testing.T) {
875 require.NoError(t, collr.Init(context.Background()))
876
877 var collected map[string]int64
878 - for i := 0; i < 10; i++ {
878 + for range 10 {
879 collected = collr.Collect(context.Background())
880 }
881
src/go/plugin/ibm.d/modules/as400/batch_path.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package as400
4
src/go/plugin/ibm.d/modules/as400/collect_activejobs.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package as400
6
src/go/plugin/ibm.d/modules/as400/collect_data.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package as400
6
src/go/plugin/ibm.d/modules/as400/collector.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package as400
4
src/go/plugin/ibm.d/modules/as400/dump.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package as400
4
src/go/plugin/ibm.d/modules/as400/groups.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package as400
4
src/go/plugin/ibm.d/modules/as400/helpers.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package as400
4
src/go/plugin/ibm.d/modules/as400/init.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package as400
4
src/go/plugin/ibm.d/modules/as400/instances.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package as400
6
src/go/plugin/ibm.d/modules/as400/latency_cache.go
+2 -3
@@ -1,6 +1,7 @@
1 package as400
2
3 import (
4 + "maps"
5 "sync"
6 "time"
7 )
@@ -39,8 +40,6 @@ func (l *latencyCache) snapshot() (map[string]int64, time.Time) {
40 return nil, l.last
41 }
42 out := make(map[string]int64, len(l.values))
42 - for k, v := range l.values {
43 - out[k] = v
44 - }
43 + maps.Copy(out, l.values)
44 return out, l.last
45 }
src/go/plugin/ibm.d/modules/as400/metrics.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package as400
6
src/go/plugin/ibm.d/modules/as400/module.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package as400
4
src/go/plugin/ibm.d/modules/as400/queues.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package as400
4
src/go/plugin/ibm.d/modules/as400/slow_path.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package as400
4
src/go/plugin/ibm.d/modules/as400/sql_queries.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package as400
6
src/go/plugin/ibm.d/modules/db2/collect.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package db2
6
src/go/plugin/ibm.d/modules/db2/collect_statements.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package db2
6
src/go/plugin/ibm.d/modules/db2/helpers.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package db2
4
src/go/plugin/ibm.d/modules/db2/indexes.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package db2
6
src/go/plugin/ibm.d/modules/db2/instances.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package db2
6
src/go/plugin/ibm.d/modules/db2/metrics.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package db2
6
src/go/plugin/ibm.d/modules/db2/module.go
-1
@@ -1,5 +1,4 @@
1 //go:build cgo
2 -// +build cgo
2
3 package db2
4
src/go/plugin/ibm.d/modules/db2/sql_queries.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package db2
6
src/go/plugin/ibm.d/modules/db2/tables.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4 -// +build cgo
4
5 package db2
6
src/go/plugin/ibm.d/pkg/dbdriver/db2.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build disable_ibm_direct_driver
4 -// +build disable_ibm_direct_driver
4
5 package dbdriver
6
src/go/plugin/ibm.d/pkg/dbdriver/db2_stub.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build !disable_ibm_direct_driver
4 -// +build !disable_ibm_direct_driver
4
5 package dbdriver
6
src/go/plugin/ibm.d/pkg/dbdriver/driver.go
+5 -8
@@ -6,6 +6,7 @@ import (
6 "context"
7 "database/sql"
8 "fmt"
9 + "slices"
10 "sync"
11 )
12
@@ -161,18 +162,14 @@ func determineDriver(config *ConnectionConfig) (driver, dsn string, err error) {
162 // Auto-select best available driver
163 // Prefer ODBC if configured or for AS/400
164 if config.PreferODBC || config.SystemType == "AS400" {
164 - for _, d := range available {
165 - if d == "odbc" {
166 - return "odbc", BuildODBCDSN(config), nil
167 - }
165 + if slices.Contains(available, "odbc") {
166 + return "odbc", BuildODBCDSN(config), nil
167 }
168 }
169
170 // Try IBM DB2 client
172 - for _, d := range available {
173 - if d == "go_ibm_db" {
174 - return "go_ibm_db", BuildDB2DSN(config), nil
175 - }
171 + if slices.Contains(available, "go_ibm_db") {
172 + return "go_ibm_db", BuildDB2DSN(config), nil
173 }
174
175 // Use whatever is available
src/go/plugin/ibm.d/pkg/dbdriver/odbc.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build !windows && cgo
4 -// +build !windows,cgo
4
5 package dbdriver
6
src/go/plugin/ibm.d/pkg/dbdriver/odbc_stub.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build windows || !cgo
4 -// +build windows !cgo
4
5 package dbdriver
6
src/go/plugin/ibm.d/pkg/dbdriver/odbcbridge.go
-1
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build !windows && cgo
4 -// +build !windows,cgo
4
5 package dbdriver
6
src/go/plugin/ibm.d/pkg/odbcbridge/connection.go
-1
@@ -2,7 +2,6 @@
2 // This version handles AS400-specific issues like negative row counts and proper data types.
3
4 //go:build cgo
5 -// +build cgo
5
6 package odbcbridge
7
src/go/plugin/ibm.d/pkg/odbcbridge/sqldriver.go
-1
@@ -1,7 +1,6 @@
1 // Package odbcbridge provides an optimized ODBC connection interface using CGO.
2
3 //go:build cgo
4 -// +build cgo
4
5 package odbcbridge
6