Skip to content

Commit e463c2c

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

26 files changed

+57
-72
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://raw.githubusercontent.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"
@@ -149,7 +150,7 @@ func (c *ClusterSync) issueRefreshRequest(url, port, basePath string, nodesPath
149150

150151
req, err := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer(bytesRepresentation))
151152
if err != nil {
152-
return fmt.Errorf("error creating new POST request for cluster comunication")
153+
return errors.New("error creating new POST request for cluster comunication")
153154
}
154155
req.Header.Add("X-Node-Key", c.cfg.Cluster.Token.Load())
155156
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
@@ -1041,6 +1041,7 @@ func handleSignals(ctx context.Context, cancel context.CancelFunc, sigs chan os.
10411041
reloadConfigurationFile(client, haproxyOptions, users)
10421042
}
10431043
case <-ctx.Done():
1044+
cancel()
10441045
return
10451046
}
10461047
}

discovery/aws_service_discovery_instance.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,9 @@ func newAWSRegionInstance(ctx context.Context, params *models.AwsRegion, client
131131
func (a *awsInstance) filterConverter(in []*models.AwsFilters) (out []types.Filter) {
132132
out = make([]types.Filter, len(in))
133133
for i, l := range in {
134-
filter := l
135134
out[i] = types.Filter{
136-
Name: filter.Key,
137-
Values: []string{aws.ToString(filter.Value)},
135+
Name: l.Key,
136+
Values: []string{aws.ToString(l.Value)},
138137
}
139138
}
140139
return

discovery/consul_service_discovery_instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (c *consulInstance) queryHealthService(se string, params *queryParams) ([]*
327327
func (c *consulInstance) doConsulQuery(method string, path string, params *queryParams, resp interface{}) (*queryMetadata, error) {
328328
mode := "http://"
329329
if c.params.Mode != nil {
330-
mode = fmt.Sprintf("%s://", *c.params.Mode)
330+
mode = *c.params.Mode + "://"
331331
}
332332
fullPath, err := url.JoinPath(
333333
mode,

discovery/store.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package discovery
1717

1818
import (
19+
"errors"
1920
"fmt"
2021
"sync"
2122
)
@@ -72,7 +73,7 @@ func (s *instanceStore) Create(name string, service interface{}) error {
7273
defer s.mu.Unlock()
7374

7475
if _, err := s.get(name); err == nil {
75-
return fmt.Errorf("instance already exists")
76+
return errors.New("instance already exists")
7677
}
7778

7879
s.store[name] = service
@@ -102,7 +103,7 @@ func (s *instanceStore) get(name string) (sd interface{}, err error) {
102103
var ok bool
103104
sd, ok = s.store[name]
104105
if !ok {
105-
return nil, fmt.Errorf("instance not found")
106+
return nil, errors.New("instance not found")
106107
}
107108
return
108109
}

generate/go-generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func getExample(att Attribute) string {
222222
if att.Example != "" {
223223
if att.Type == "int" {
224224
i, _ := strconv.ParseInt(att.Example, 10, 64)
225-
return fmt.Sprintf("%d", i)
225+
return strconv.FormatInt(i, 10)
226226
}
227227
return att.Example
228228
}
@@ -243,7 +243,7 @@ func getExample(att Attribute) string {
243243
if v, ok := itemDefaults[att.FileName]; ok {
244244
switch t := v.(type) {
245245
case int:
246-
return fmt.Sprintf("%d", v.(int))
246+
return strconv.Itoa(v.(int))
247247
default:
248248
return t.(string)
249249
}

handlers/bind.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package handlers
1717

1818
import (
19-
"fmt"
19+
"errors"
2020

2121
"github.com/go-openapi/runtime/middleware"
2222
client_native "github.com/haproxytech/client-native/v5"
@@ -60,10 +60,10 @@ func bindTypeParams(frontend *string, parentType *string, parentName *string) (p
6060
return "frontend", *frontend, nil
6161
}
6262
if parentType == nil || *parentType == "" {
63-
return "", "", fmt.Errorf("parentType empty")
63+
return "", "", errors.New("parentType empty")
6464
}
6565
if parentName == nil || *parentName == "" {
66-
return "", "", fmt.Errorf("parentName empty")
66+
return "", "", errors.New("parentName empty")
6767
}
6868
return *parentType, *parentName, nil
6969
}

handlers/cluster.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package handlers
1717

1818
import (
19+
"errors"
1920
"fmt"
2021
"reflect"
2122
"strings"
@@ -255,7 +256,7 @@ func (h *EditClusterHandlerImpl) Handle(params cluster.EditClusterParams, princi
255256
}
256257
return cluster.NewEditClusterOK().WithPayload(getClusterSettings(h.Config))
257258
}
258-
return h.err406(fmt.Errorf("dataplaneapi in single mode"))
259+
return h.err406(errors.New("dataplaneapi in single mode"))
259260
}
260261

261262
func (h *EditClusterHandlerImpl) err406(err error) middleware.Responder {

handlers/frontend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (h *ReplaceFrontendHandlerImpl) Handle(params frontend.ReplaceFrontendParam
228228
return frontend.NewReplaceFrontendDefault(int(*e.Code)).WithPayload(e)
229229
}
230230
if params.TransactionID == nil {
231-
reload := changeThroughRuntimeAPI(*params.Data, *ondisk, "", "", h.Client)
231+
reload := changeThroughRuntimeAPI(*params.Data, *ondisk, "", h.Client)
232232
if reload {
233233
if *params.ForceReload {
234234
err := h.ReloadAgent.ForceReload()

handlers/runtime.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var RuntimeSupportedFields = map[string][]string{
3333

3434
// ChangeThroughRuntimeAPI checks if something can be changed through the runtime API, and
3535
// returns false if reload is not needed, or true if needed.
36-
func changeThroughRuntimeAPI(data, ondisk interface{}, parentName, parentType string, client client_native.HAProxyClient) (reload bool) {
36+
func changeThroughRuntimeAPI(data, ondisk interface{}, parentName string, client client_native.HAProxyClient) (reload bool) {
3737
// reflect kinds and values are loosely checked as they are bound strictly in
3838
// schema, but in case of any panic, we will log and reload to ensure
3939
// changes go through
@@ -183,7 +183,7 @@ func compareObjects(data, ondisk interface{}) []string {
183183
diff := make([]string, 0)
184184
dataVal := reflect.ValueOf(data)
185185
ondiskVal := reflect.ValueOf(ondisk)
186-
for i := 0; i < dataVal.NumField(); i++ {
186+
for i := range dataVal.NumField() {
187187
fName := dataVal.Type().Field(i).Name
188188
dataField := dataVal.FieldByName(fName)
189189
ondiskField := ondiskVal.FieldByName(fName)

handlers/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package handlers
1717

1818
import (
19-
"fmt"
19+
"errors"
2020

2121
"github.com/go-openapi/runtime/middleware"
2222
client_native "github.com/haproxytech/client-native/v5"
@@ -61,10 +61,10 @@ func serverTypeParams(backend *string, parentType *string, parentName *string) (
6161
return "backend", *backend, nil
6262
}
6363
if parentType == nil || *parentType == "" {
64-
return "", "", fmt.Errorf("parentType empty")
64+
return "", "", errors.New("parentType empty")
6565
}
6666
if parentName == nil || *parentName == "" {
67-
return "", "", fmt.Errorf("parentName empty")
67+
return "", "", errors.New("parentName empty")
6868
}
6969
return *parentType, *parentName, nil
7070
}
@@ -308,7 +308,7 @@ func (h *ReplaceServerHandlerImpl) Handle(params server.ReplaceServerParams, pri
308308
return server.NewReplaceServerDefault(int(*e.Code)).WithPayload(e)
309309
}
310310
if params.TransactionID == nil {
311-
reload := changeThroughRuntimeAPI(*params.Data, *ondisk, pType, "", h.Client)
311+
reload := changeThroughRuntimeAPI(*params.Data, *ondisk, pName, h.Client)
312312
if reload {
313313
if *params.ForceReload {
314314
err := h.ReloadAgent.ForceReload()

handlers/server_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (h *ReplaceServerTemplateHandlerImpl) Handle(params server_template.Replace
232232
return server_template.NewReplaceServerTemplateDefault(int(*e.Code)).WithPayload(e)
233233
}
234234
if params.TransactionID == nil {
235-
reload := changeThroughRuntimeAPI(*params.Data, *ondisk, params.Backend, "", h.Client)
235+
reload := changeThroughRuntimeAPI(*params.Data, *ondisk, params.Backend, h.Client)
236236
if reload {
237237
if *params.ForceReload {
238238
err := h.ReloadAgent.ForceReload()

haproxy/reload_agent.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package haproxy
1818
import (
1919
"bytes"
2020
"context"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"os"
@@ -42,10 +43,10 @@ const (
4243

4344
type IReloadAgent interface {
4445
Reload() string
45-
ReloadWithCallback(func()) string
46+
ReloadWithCallback(callback func()) string
4647
Restart() error
4748
ForceReload() error
48-
ForceReloadWithCallback(func()) error
49+
ForceReloadWithCallback(callback func()) error
4950
Status() (bool, error)
5051
GetReloads() models.Reloads
5152
GetReload(id string) *models.Reload
@@ -479,7 +480,7 @@ func (ra *ReloadAgent) Status() (bool, error) {
479480

480481
func (ra *ReloadAgent) status() (bool, error) {
481482
if ra.statusCmd == "" {
482-
return false, fmt.Errorf("status command not configured")
483+
return false, errors.New("status command not configured")
483484
}
484485
resp, err := execCmd(ra.statusCmd)
485486
if err != nil {
@@ -511,7 +512,7 @@ type ReloadError struct {
511512

512513
// Error implementation for ConfError
513514
func (e *ReloadError) Error() string {
514-
return fmt.Sprintf(e.msg)
515+
return e.msg
515516
}
516517

517518
// NewReloadError constructor for ReloadError

haproxy/reload_agent_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ import (
2222
"time"
2323

2424
"github.com/stretchr/testify/assert"
25+
"github.com/stretchr/testify/require"
2526
)
2627

2728
func TestReloadAgentDoesntMissReloads(t *testing.T) {
2829
ctx, cancel := context.WithCancel(context.Background())
2930
f, err := os.CreateTemp("", "config.cfg")
30-
assert.Nil(t, err)
31+
require.NoError(t, err)
3132
assert.NotNil(t, f)
3233
t.Cleanup(func() {
3334
cancel()
34-
assert.Nil(t, os.Remove(f.Name()))
35+
assert.NoError(t, os.Remove(f.Name()))
3536
})
3637

3738
reloadAgentParams := ReloadAgentParams{
@@ -45,7 +46,7 @@ func TestReloadAgentDoesntMissReloads(t *testing.T) {
4546
}
4647

4748
ra, err := NewReloadAgent(reloadAgentParams)
48-
assert.Nil(t, err)
49+
require.NoError(t, err)
4950
assert.NotNil(t, ra)
5051

5152
var reloadID, firstReloadID, secondReloadID string

0 commit comments

Comments
 (0)