Skip to content

Commit 087e300

Browse files
committed
build: update to go 1.25 and golanci-lint 2.5.0
related to edgexfoundry/edgex-go#5302 Also fixes all errors as reported by golanci-lint 2.5.0 Signed-off-by: Jude Hung <[email protected]>
1 parent e75efff commit 087e300

File tree

18 files changed

+106
-85
lines changed

18 files changed

+106
-85
lines changed

.golangci.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1+
version: "2"
12
linters:
2-
disable:
33
enable:
44
- gosec
5-
linters-settings:
6-
gosec:
7-
excludes:
8-
# G115: integer overflow conversion
9-
# exclude the rule since it tends to be false positive
10-
- G115
5+
exclusions:
6+
generated: lax
7+
presets:
8+
- comments
9+
- common-false-positives
10+
- legacy
11+
- std-error-handling
12+
paths:
13+
- third_party$
14+
- builtin$
15+
- examples$
16+
formatters:
17+
exclusions:
18+
generated: lax
19+
paths:
20+
- third_party$
21+
- builtin$
22+
- examples$

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616

1717
edgeXBuildGoMod (
1818
project: 'go-mod-core-contracts',
19-
goVersion: '1.23'
20-
)
19+
goVersion: '1.25'
20+
)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ lint:
1414
@if [ "z${ARCH}" = "zx86_64" ] && which golangci-lint >/dev/null ; then golangci-lint run --config .golangci.yml ; else echo "WARNING: Linting skipped (not on x86_64 or linter not installed)"; fi
1515

1616
install-lint:
17-
sudo curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.61.0
17+
sudo curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v2.5.0
1818

1919
test: unittest lint
2020
$(GO) vet ./...

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The default encoding for the models is JSON, although in at least one case --
1111
YAML encoding is also supported since a device profile is defined as a YAML document.
1212

1313
### Installation ###
14-
* Make sure you're using at least Go 1.11.1 (EdgeX currently uses Go 1.17.x) and have modules enabled, i.e. have an initialized go.mod file
14+
* Make sure you're using at least Go 1.25.0 and have modules enabled, i.e. have an initialized go.mod file
1515
* If your code is in your GOPATH then make sure ```GO111MODULE=on``` is set
1616
* Run ```go get github.com/edgexfoundry/go-mod-core-contracts```
1717
* This will add the go-mod-core-contracts to the go.mod file and download it into the module cache

clients/http/authinjector_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ func NewNullAuthenticationInjector() interfaces.AuthenticationInjector {
1919
return &emptyAuthenticationInjector{}
2020
}
2121

22-
func (_ *emptyAuthenticationInjector) AddAuthenticationData(_ *http.Request) error {
22+
func (*emptyAuthenticationInjector) AddAuthenticationData(_ *http.Request) error {
2323
// Do nothing to the request; used for unit tests
2424
return nil
2525
}
2626

27-
func (_ *emptyAuthenticationInjector) RoundTripper() http.RoundTripper {
27+
func (*emptyAuthenticationInjector) RoundTripper() http.RoundTripper {
2828
// Do nothing to the request; used for unit tests
2929
return nil
3030
}

clients/http/utils/common.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func CreateRequestFromFilePath(ctx context.Context, httpMethod string, baseUrl s
189189
return nil, errors.NewCommonEdgeX(errors.KindServerError, "failed to parse baseUrl and requestPath", err)
190190
}
191191

192-
fileContents, err := os.ReadFile(filePath)
192+
fileContents, err := os.ReadFile(filePath) // #nosec G304 -- filePath is controlled and safe to be read
193193
if err != nil {
194194
return nil, errors.NewCommonEdgeX(errors.KindIOError, fmt.Sprintf("fail to read file from %s", filePath), err)
195195
}
@@ -204,7 +204,10 @@ func CreateRequestFromFilePath(ctx context.Context, httpMethod string, baseUrl s
204204
if err != nil {
205205
return nil, errors.NewCommonEdgeX(errors.KindIOError, "fail to copy file to form data", err)
206206
}
207-
writer.Close()
207+
err = writer.Close()
208+
if err != nil {
209+
return nil, errors.NewCommonEdgeX(errors.KindIOError, "fail to close multipart writer", err)
210+
}
208211

209212
req, err := http.NewRequest(httpMethod, u.String(), body)
210213
if err != nil {
@@ -222,7 +225,9 @@ func SendRequest(ctx context.Context, req *http.Request, authInjector interfaces
222225
if err != nil {
223226
return nil, errors.NewCommonEdgeXWrapper(err)
224227
}
225-
defer resp.Body.Close()
228+
defer func(Body io.ReadCloser) {
229+
_ = Body.Close()
230+
}(resp.Body)
226231

227232
bodyBytes, err := getBody(resp)
228233
if err != nil {

clients/http/utils/common_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ func TestCreateRequestFromFilePath(t *testing.T) {
9898
requestPathWithSlash := "/test-path"
9999
f, err := os.CreateTemp("", "sample")
100100
assert.NoError(t, err)
101-
defer os.Remove(f.Name())
101+
defer func(name string) {
102+
_ = os.Remove(name)
103+
}(f.Name())
102104

103105
tests := []struct {
104106
name string

clients/http/utils/request.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"context"
1111
"encoding/json"
1212
"fmt"
13+
"io"
1314
"net/http"
1415
"net/url"
1516

@@ -39,7 +40,9 @@ func GetRequestAndReturnBinaryRes(ctx context.Context, baseUrl string, requestPa
3940
if edgeXerr != nil {
4041
return nil, "", errors.NewCommonEdgeXWrapper(edgeXerr)
4142
}
42-
defer resp.Body.Close()
43+
defer func(Body io.ReadCloser) {
44+
_ = Body.Close()
45+
}(resp.Body)
4346

4447
res, edgeXerr = getBody(resp)
4548
if edgeXerr != nil {

common/utils.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ func BuildTopic(parts ...string) string {
4444
// URLEncode encodes the input string with additional common character support
4545
func URLEncode(s string) string {
4646
res := url.PathEscape(s)
47-
res = strings.Replace(res, "+", "%2B", -1) // MQTT topic reserved char
48-
res = strings.Replace(res, "-", "%2D", -1)
49-
res = strings.Replace(res, ".", "%2E", -1) // RegexCmd and Redis topic reserved char
50-
res = strings.Replace(res, "_", "%5F", -1)
51-
res = strings.Replace(res, "~", "%7E", -1)
47+
res = strings.ReplaceAll(res, "+", "%2B") // MQTT topic reserved char
48+
res = strings.ReplaceAll(res, "-", "%2D")
49+
res = strings.ReplaceAll(res, ".", "%2E") // RegexCmd and Redis topic reserved char
50+
res = strings.ReplaceAll(res, "_", "%5F")
51+
res = strings.ReplaceAll(res, "~", "%7E")
5252

5353
return res
5454
}

dtos/address.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ func ToAddressModel(a Address) models.Address {
166166
BaseAddress: models.BaseAddress{
167167
Type: a.Type, Host: a.Host, Port: a.Port, Scheme: a.Scheme,
168168
},
169-
Path: a.RESTAddress.Path,
170-
HTTPMethod: a.RESTAddress.HTTPMethod,
171-
InjectEdgeXAuth: a.RESTAddress.InjectEdgeXAuth,
169+
Path: a.Path,
170+
HTTPMethod: a.HTTPMethod,
171+
InjectEdgeXAuth: a.InjectEdgeXAuth,
172172
}
173173
case common.MQTT:
174174
address = models.MQTTPubAddress{
@@ -181,7 +181,7 @@ func ToAddressModel(a Address) models.Address {
181181
SkipCertVerify: a.SkipCertVerify,
182182
},
183183
MessageBus: models.MessageBus{Topic: a.Topic},
184-
Publisher: a.MQTTPubAddress.Publisher,
184+
Publisher: a.Publisher,
185185
QoS: a.QoS,
186186
KeepAlive: a.KeepAlive,
187187
Retained: a.Retained,
@@ -200,7 +200,7 @@ func ToAddressModel(a Address) models.Address {
200200
BaseAddress: models.BaseAddress{
201201
Type: a.Type,
202202
},
203-
Recipients: a.EmailAddress.Recipients,
203+
Recipients: a.Recipients,
204204
}
205205
}
206206
return address

0 commit comments

Comments
 (0)