Skip to content

Commit 8e1b865

Browse files
committed
CLEANUP/MAJOR: lint: upgrade linter for go 1.22
1 parent f912aa3 commit 8e1b865

25 files changed

+56
-71
lines changed

.golangci.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ linters-settings:
1616
min-occurrences: 2
1717
revive:
1818
rules:
19-
- name: var-naming
20-
severity: warning
21-
disabled: true
19+
- name: var-naming
20+
severity: warning
21+
disabled: true
2222
linters:
2323
enable-all: true
2424
disable:
@@ -74,13 +74,12 @@ linters:
7474
- tagalign
7575
- depguard
7676

77-
7877
issues:
7978
exclude:
8079
# bugs of typecheck linter
8180
- "undeclared name: `shellquote`"
82-
- "github.com/kballard/go-shellquote\" imported but not used"
83-
- "github.com/haproxytech/config-parser/v5/types\" imported but not used"
81+
- 'github.com/kballard/go-shellquote" imported but not used'
82+
- 'github.com/haproxytech/config-parser/v5/types" imported but not used'
8483
exclude-rules:
8584
- linters:
8685
- staticcheck
@@ -91,7 +90,5 @@ issues:
9190
- linters:
9291
- gosec
9392
text: "G[404]"
94-
95-
run:
96-
skip-dirs:
93+
exclude-dirs:
9794
- test

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ GIT_MODIFIED=${GIT_MODIFIED1}${GIT_MODIFIED2}
99
SWAGGER_VERSION=${shell curl -s https://github.com/haproxytech/client-native/master/Makefile | grep SWAGGER_VERSION -m 1 | awk -F"=" '{print $$2}'}
1010
BUILD_DATE=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
1111
CGO_ENABLED?=0
12-
GOLANGCI_LINT_VERSION=1.54.2
12+
GOLANGCI_LINT_VERSION=1.57.1
1313

1414
all: update clean build
1515

configuration/cluster_sync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"crypto/x509/pkix"
2626
"encoding/asn1"
2727
"encoding/pem"
28+
"errors"
2829
"fmt"
2930
"io"
3031
"net/http"
@@ -148,7 +149,7 @@ func (c *ClusterSync) issueRefreshRequest(url, port, basePath string, nodesPath
148149

149150
req, err := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer(bytesRepresentation))
150151
if err != nil {
151-
return fmt.Errorf("error creating new POST request for cluster comunication")
152+
return errors.New("error creating new POST request for cluster comunication")
152153
}
153154
req.Header.Add("X-Node-Key", c.cfg.Cluster.Token.Load())
154155
req.Header.Add("Content-Type", "application/json")

configuration/map_sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (ms *MapSync) Sync(mp *models.Map, client client_native.HAProxyClient) (boo
9696
sort.Slice(fileEntries, func(i, j int) bool { return fileEntries[i].Key < fileEntries[j].Key })
9797

9898
// runtime map entries
99-
id := fmt.Sprintf("#%s", mp.ID)
99+
id := "#" + mp.ID
100100
runtimeEntries, err := runtime.ShowMapEntries(id)
101101
if err != nil {
102102
return false, fmt.Errorf("getting runtime entries error: id: %s %s", id, err.Error())
@@ -144,7 +144,7 @@ func equalSomeEntries(fEntries, rEntries models.MapEntries, index ...int) bool {
144144
maxRandom = max
145145
}
146146

147-
for i := 0; i < maxRandom; i++ {
147+
for range maxRandom {
148148
// There's no need for strong number generation, here, just need for performance
149149
r := rand.Intn(max)
150150
if len(index) > 0 {

configuration/map_sync_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func data(differentAtIndex ...int) (fileEntries models.MapEntries, runtimeEntries models.MapEntries) {
26-
for i := 0; i < 50; i++ {
26+
for i := range 50 {
2727
fe := &models.MapEntry{Key: "k" + strconv.Itoa(i), Value: "v" + strconv.Itoa(i)}
2828
re := &models.MapEntry{Key: "k" + strconv.Itoa(i), Value: "v" + strconv.Itoa(i)}
2929
fileEntries = append(fileEntries, fe)

configuration/pid.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package configuration
1717

1818
import (
19-
"fmt"
2019
"os"
2120
"strconv"
2221

@@ -47,7 +46,7 @@ func HandlePIDFile(haproxyOptions HAProxyConfiguration) {
4746
}
4847
}
4948

50-
err := renameio.WriteFile(haproxyOptions.PIDFile, []byte(fmt.Sprintf("%d", os.Getpid())), 0o644)
49+
err := renameio.WriteFile(haproxyOptions.PIDFile, []byte(strconv.Itoa(os.Getpid())), 0o644)
5150
if err != nil {
5251
log.Fatalf("error while writing PID file: %s %s", haproxyOptions.PIDFile, err.Error())
5352
} else {

configuration/reload-strategy.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
package configuration
1717

18-
import "fmt"
18+
import (
19+
"errors"
20+
"fmt"
21+
)
1922

2023
const (
2124
ReloadStratCustom = "custom"
@@ -53,7 +56,7 @@ func validateReloadConfiguration(c *HAProxyConfiguration) error {
5356
case ReloadStratCustom:
5457
// The custom commands need to be set.
5558
if c.ReloadCmd == "" || c.RestartCmd == "" {
56-
return fmt.Errorf("the custom reload strategy requires these options to be set: " +
59+
return errors.New("the custom reload strategy requires these options to be set: " +
5760
"ReloadCmd, RestartCmd")
5861
}
5962
case ReloadStratS6:

configuration/watcher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package configuration
1818
import (
1919
"context"
2020
"crypto/md5"
21-
"fmt"
21+
"encoding/hex"
2222
"os"
2323
"path/filepath"
2424
"strings"
@@ -108,6 +108,6 @@ func (w *ConfigWatcher) invalidHash() bool {
108108
return true
109109
}
110110
bHash := md5.Sum([]byte(strings.Join(lines[1:], "\n")))
111-
hash := fmt.Sprintf("%x", bHash)
111+
hash := hex.EncodeToString(bHash[:])
112112
return parts[1] != hash
113113
}

configure_data_plane.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ func handleSignals(ctx context.Context, cancel context.CancelFunc, sigs chan os.
10321032
reloadConfigurationFile(client, haproxyOptions, users)
10331033
}
10341034
case <-ctx.Done():
1035+
cancel()
10351036
return
10361037
}
10371038
}

discovery/aws_service_discovery_instance.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ func newAWSRegionInstance(ctx context.Context, params *models.AwsRegion, client
127127
func (a *awsInstance) filterConverter(in []*models.AwsFilters) (out []types.Filter) {
128128
out = make([]types.Filter, len(in))
129129
for i, l := range in {
130-
filter := l
131130
out[i] = types.Filter{
132-
Name: filter.Key,
133-
Values: []string{aws.ToString(filter.Value)},
131+
Name: l.Key,
132+
Values: []string{aws.ToString(l.Value)},
134133
}
135134
}
136135
return

0 commit comments

Comments
 (0)