Skip to content

Commit 2dc2b19

Browse files
tas50claude
andcommitted
🧹 Modernize arista and network providers with Go idioms
Use strings.Builder for string concatenation, errgroup.Go() instead of manual Add/Done, maps.Copy for map merging, and remove redundant +build tag. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2116076 commit 2dc2b19

File tree

5 files changed

+18
-33
lines changed

5 files changed

+18
-33
lines changed

providers/arista/resources/eos/arista_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: BUSL-1.1
33

44
//go:build debugtest
5-
// +build debugtest
65

76
package eos
87

providers/arista/resources/eos/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func GetSection(in io.Reader, section string) string {
8484

8585
lastDepth := 0
8686
lastKey := ""
87-
recorded := ""
87+
var recorded strings.Builder
8888
for scanner.Scan() {
8989
line := scanner.Text()
9090
key := strings.TrimSpace(line)
@@ -115,9 +115,9 @@ func GetSection(in io.Reader, section string) string {
115115
lastKey = key
116116

117117
if strings.Join(keyStack, " ") == " "+section {
118-
recorded += key + "\n"
118+
recorded.WriteString(key + "\n")
119119
}
120120
}
121121

122-
return recorded
122+
return recorded.String()
123123
}

providers/network/resources/dnsshake/dnsshake.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ func (d *DnsClient) Query(dnsTypes ...string) (map[string]DnsRecord, error) {
167167
for i := range dnsTypes {
168168
dnsType := dnsTypes[i]
169169

170-
workers.Add(1)
171-
go func() {
172-
defer workers.Done()
170+
workers.Go(func() {
173171

174172
records, err := d.queryDnsType(d.fqdn, dnsType)
175173
if err != nil {
@@ -184,7 +182,7 @@ func (d *DnsClient) Query(dnsTypes ...string) (map[string]DnsRecord, error) {
184182
res[k] = records[k]
185183
}
186184
d.sync.Unlock()
187-
}()
185+
})
188186
}
189187

190188
workers.Wait()

providers/network/resources/http.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,15 @@ func (x *mqlHttpHeader) contentType() (*mqlHttpHeaderContentType, error) {
363363
}
364364

365365
func (x *mqlHttpHeaderContentType) id() (string, error) {
366-
id := x.Type.Data
366+
var id strings.Builder
367+
id.WriteString(x.Type.Data)
367368
if x.Params.Data != nil {
368369
keys := sortx.Keys(x.Params.Data)
369370
for _, key := range keys {
370-
id += ";" + key + "=" + x.Params.Data[key].(string)
371+
id.WriteString(";" + key + "=" + x.Params.Data[key].(string))
371372
}
372373
}
373-
return id, nil
374+
return id.String(), nil
374375
}
375376

376377
func (x *mqlHttpHeader) setCookie() (*mqlHttpHeaderSetCookie, error) {

providers/network/resources/tlsshake/tlsshake.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"encoding/hex"
1414
"errors"
1515
"io"
16+
"maps"
1617
"math/rand"
1718
"net"
1819
"net/http"
@@ -154,9 +155,7 @@ func (s *Tester) Test(conf ScanConfig) error {
154155
for i := range conf.Versions {
155156
version := conf.Versions[i]
156157

157-
workers.Add(1)
158-
go func() {
159-
defer workers.Done()
158+
workers.Go(func() {
160159

161160
// we don't activate any of the additional tests in the beginning
162161
// let's find out if we work on this version of TLS/SSL
@@ -201,7 +200,7 @@ func (s *Tester) Test(conf ScanConfig) error {
201200
_, _ = s.testTLS(s.proto, s.target, curConf)
202201
}
203202
}
204-
}()
203+
})
205204
}
206205

207206
workers.Wait()
@@ -947,24 +946,12 @@ func init() {
947946
len(TLS_CIPHERS))
948947

949948
// Note: overlapping names will be overwritten
950-
for k, v := range SSL2_CIPHERS {
951-
ALL_CIPHERS[k] = v
952-
}
953-
for k, v := range SSL3_CIPHERS {
954-
ALL_CIPHERS[k] = v
955-
}
956-
for k, v := range SSL_FIPS_CIPHERS {
957-
ALL_CIPHERS[k] = v
958-
}
959-
for k, v := range TLS10_CIPHERS {
960-
ALL_CIPHERS[k] = v
961-
}
962-
for k, v := range TLS13_CIPHERS {
963-
ALL_CIPHERS[k] = v
964-
}
965-
for k, v := range TLS_CIPHERS {
966-
ALL_CIPHERS[k] = v
967-
}
949+
maps.Copy(ALL_CIPHERS, SSL2_CIPHERS)
950+
maps.Copy(ALL_CIPHERS, SSL3_CIPHERS)
951+
maps.Copy(ALL_CIPHERS, SSL_FIPS_CIPHERS)
952+
maps.Copy(ALL_CIPHERS, TLS10_CIPHERS)
953+
maps.Copy(ALL_CIPHERS, TLS13_CIPHERS)
954+
maps.Copy(ALL_CIPHERS, TLS_CIPHERS)
968955
}
969956

970957
const (

0 commit comments

Comments
 (0)