Skip to content

Commit 2cafbc8

Browse files
authored
Merge pull request #1439 from aptly-dev/feature/go-1.24
go: use version 1.24
2 parents c05068c + 9a21717 commit 2cafbc8

119 files changed

Lines changed: 808 additions & 744 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
run:
2-
tests: false
3-
4-
1+
version: "2"
52
linters:
6-
disable-all: true
7-
enable:
8-
- goconst
9-
- gofmt
10-
- goimports
11-
- govet
12-
- ineffassign
13-
- misspell
14-
- revive
15-
- staticcheck
16-
- vetshadow
3+
settings:
4+
staticcheck:
5+
checks:
6+
- "all"
7+
- "-QF1004" # could use strings.ReplaceAll instead
8+
- "-QF1012" # Use fmt.Fprintf(...) instead of WriteString(fmt.Sprintf(...))
9+
- "-QF1003" # could use tagged switch
10+
- "-ST1000" # at least one file in a package should have a package comment
11+
- "-QF1001" # could apply De Morgan's law

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ GOPATH=$(shell go env GOPATH)
22
VERSION=$(shell make -s version)
33
PYTHON?=python3
44
BINPATH?=$(GOPATH)/bin
5-
GOLANGCI_LINT_VERSION=v1.64.5 # version supporting go 1.23
5+
GOLANGCI_LINT_VERSION=v2.0.2 # version supporting go 1.24
66
COVERAGE_DIR?=$(shell mktemp -d)
77
GOOS=$(shell go env GOHOSTOS)
88
GOARCH=$(shell go env GOHOSTARCH)
@@ -71,9 +71,9 @@ flake8: ## run flake8 on system test python files
7171

7272
lint: prepare
7373
# Install golangci-lint
74-
@test -f $(BINPATH)/golangci-lint || go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
74+
@test -f $(BINPATH)/golangci-lint || go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
7575
# Running lint
76-
@PATH=$(BINPATH)/:$(PATH) golangci-lint run --max-issues-per-linter 0 --max-same-issues 0
76+
@NO_COLOR=true PATH=$(BINPATH)/:$(PATH) golangci-lint run --max-issues-per-linter=0 --max-same-issues=0
7777

7878

7979
build: prepare swagger ## Build aptly
@@ -164,6 +164,9 @@ binaries: prepare swagger ## Build binary releases (FreeBSD, macOS, Linux gener
164164
docker-image: ## Build aptly-dev docker image
165165
@docker build -f system/Dockerfile . -t aptly-dev
166166

167+
docker-image-no-cache: ## Build aptly-dev docker image (no cache)
168+
@docker build --no-cache -f system/Dockerfile . -t aptly-dev
169+
167170
docker-build: ## Build aptly in docker container
168171
@docker run -it --rm -v ${PWD}:/work/src aptly-dev /work/src/system/docker-wrapper build
169172

api/api.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ type aptlyVersion struct {
4141
// @Success 200 {object} aptlyVersion
4242
// @Router /api/version [get]
4343
func apiVersion(c *gin.Context) {
44-
c.JSON(200, gin.H{"Version": aptly.Version})
44+
version := aptlyVersion{
45+
Version: aptly.Version,
46+
}
47+
c.JSON(200, version)
4548
}
4649

4750
type aptlyStatus struct {
@@ -67,7 +70,8 @@ func apiReady(isReady *atomic.Value) func(*gin.Context) {
6770
return
6871
}
6972

70-
c.JSON(200, gin.H{"Status": "Aptly is ready"})
73+
status := aptlyStatus{Status: "Aptly is ready"}
74+
c.JSON(200, status)
7175
}
7276
}
7377

@@ -165,7 +169,7 @@ func runTaskInBackground(name string, resources []string, proc task.Process) (ta
165169
return nil, err
166170
}
167171

168-
defer releaseDatabaseConnection()
172+
defer func() { _ = releaseDatabaseConnection() }()
169173
return proc(out, detail)
170174
})
171175
}
@@ -174,18 +178,18 @@ func truthy(value interface{}) bool {
174178
if value == nil {
175179
return false
176180
}
177-
switch value.(type) {
181+
switch v := value.(type) {
178182
case string:
179-
switch strings.ToLower(value.(string)) {
183+
switch strings.ToLower(v) {
180184
case "n", "no", "f", "false", "0", "off":
181185
return false
182186
default:
183187
return true
184188
}
185189
case int:
186-
return !(value.(int) == 0)
190+
return v != 0
187191
case bool:
188-
return value.(bool)
192+
return v
189193
}
190194
return true
191195
}
@@ -210,11 +214,11 @@ func maybeRunTaskInBackground(c *gin.Context, name string, resources []string, p
210214
}
211215

212216
// wait for task to finish
213-
context.TaskList().WaitForTaskByID(task.ID)
217+
_, _ = context.TaskList().WaitForTaskByID(task.ID)
214218

215219
retValue, _ := context.TaskList().GetTaskReturnValueByID(task.ID)
216220
err, _ := context.TaskList().GetTaskErrorByID(task.ID)
217-
context.TaskList().DeleteTaskByID(task.ID)
221+
_, _ = context.TaskList().DeleteTaskByID(task.ID)
218222
if err != nil {
219223
AbortWithJSONError(c, retValue.Code, err)
220224
return
@@ -282,27 +286,27 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList, collectionFactory
282286
// filter packages by version
283287
if c.Request.URL.Query().Get("maximumVersion") == "1" {
284288
list.PrepareIndex()
285-
list.ForEach(func(p *deb.Package) error {
289+
_ = list.ForEach(func(p *deb.Package) error {
286290
versionQ, err := query.Parse(fmt.Sprintf("Name (%s), $Version (<= %s)", p.Name, p.Version))
287291
if err != nil {
288292
fmt.Println("filter packages by version, query string parse err: ", err)
289-
c.AbortWithError(500, fmt.Errorf("unable to parse %s maximum version query string: %s", p.Name, err))
293+
_ = c.AbortWithError(500, fmt.Errorf("unable to parse %s maximum version query string: %s", p.Name, err))
290294
} else {
291295
tmpList, err := list.Filter(deb.FilterOptions{
292296
Queries: []deb.PackageQuery{versionQ},
293297
})
294298

295299
if err == nil {
296300
if tmpList.Len() > 0 {
297-
tmpList.ForEach(func(tp *deb.Package) error {
301+
_ = tmpList.ForEach(func(tp *deb.Package) error {
298302
list.Remove(tp)
299303
return nil
300304
})
301-
list.Add(p)
305+
_ = list.Add(p)
302306
}
303307
} else {
304308
fmt.Println("filter packages by version, filter err: ", err)
305-
c.AbortWithError(500, fmt.Errorf("unable to get %s maximum version: %s", p.Name, err))
309+
_ = c.AbortWithError(500, fmt.Errorf("unable to get %s maximum version: %s", p.Name, err))
306310
}
307311
}
308312

@@ -311,7 +315,7 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList, collectionFactory
311315
}
312316

313317
if c.Request.URL.Query().Get("format") == "details" {
314-
list.ForEach(func(p *deb.Package) error {
318+
_ = list.ForEach(func(p *deb.Package) error {
315319
result = append(result, p)
316320
return nil
317321
})
@@ -322,7 +326,7 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList, collectionFactory
322326
}
323327
}
324328

325-
func AbortWithJSONError(c *gin.Context, code int, err error) *gin.Error {
329+
func AbortWithJSONError(c *gin.Context, code int, err error) {
326330
c.Writer.Header().Set("Content-Type", "application/json; charset=utf-8")
327-
return c.AbortWithError(code, err)
331+
_ = c.AbortWithError(code, err)
328332
}

api/api_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ func Test(t *testing.T) {
2424
TestingT(t)
2525
}
2626

27-
type ApiSuite struct {
27+
type APISuite struct {
2828
context *ctx.AptlyContext
2929
flags *flag.FlagSet
3030
configFile *os.File
3131
router http.Handler
3232
}
3333

34-
var _ = Suite(&ApiSuite{})
34+
var _ = Suite(&APISuite{})
3535

3636
func createTestConfig() *os.File {
3737
file, err := os.CreateTemp("", "aptly")
@@ -45,11 +45,11 @@ func createTestConfig() *os.File {
4545
if err != nil {
4646
return nil
4747
}
48-
file.Write(jsonString)
48+
_, _ = file.Write(jsonString)
4949
return file
5050
}
5151

52-
func (s *ApiSuite) setupContext() error {
52+
func (s *APISuite) setupContext() error {
5353
aptly.Version = "testVersion"
5454
file := createTestConfig()
5555
if nil == file {
@@ -75,23 +75,23 @@ func (s *ApiSuite) setupContext() error {
7575
return nil
7676
}
7777

78-
func (s *ApiSuite) SetUpSuite(c *C) {
78+
func (s *APISuite) SetUpSuite(c *C) {
7979
err := s.setupContext()
8080
c.Assert(err, IsNil)
8181
}
8282

83-
func (s *ApiSuite) TearDownSuite(c *C) {
84-
os.Remove(s.configFile.Name())
83+
func (s *APISuite) TearDownSuite(c *C) {
84+
_ = os.Remove(s.configFile.Name())
8585
s.context.Shutdown()
8686
}
8787

88-
func (s *ApiSuite) SetUpTest(c *C) {
88+
func (s *APISuite) SetUpTest(c *C) {
8989
}
9090

91-
func (s *ApiSuite) TearDownTest(c *C) {
91+
func (s *APISuite) TearDownTest(c *C) {
9292
}
9393

94-
func (s *ApiSuite) HTTPRequest(method string, url string, body io.Reader) (*httptest.ResponseRecorder, error) {
94+
func (s *APISuite) HTTPRequest(method string, url string, body io.Reader) (*httptest.ResponseRecorder, error) {
9595
w := httptest.NewRecorder()
9696
req, err := http.NewRequest(method, url, body)
9797
if err != nil {
@@ -102,32 +102,32 @@ func (s *ApiSuite) HTTPRequest(method string, url string, body io.Reader) (*http
102102
return w, nil
103103
}
104104

105-
func (s *ApiSuite) TestGinRunsInReleaseMode(c *C) {
105+
func (s *APISuite) TestGinRunsInReleaseMode(c *C) {
106106
c.Check(gin.Mode(), Equals, gin.ReleaseMode)
107107
}
108108

109-
func (s *ApiSuite) TestGetVersion(c *C) {
109+
func (s *APISuite) TestGetVersion(c *C) {
110110
response, err := s.HTTPRequest("GET", "/api/version", nil)
111111
c.Assert(err, IsNil)
112112
c.Check(response.Code, Equals, 200)
113113
c.Check(response.Body.String(), Matches, "{\"Version\":\""+aptly.Version+"\"}")
114114
}
115115

116-
func (s *ApiSuite) TestGetReadiness(c *C) {
116+
func (s *APISuite) TestGetReadiness(c *C) {
117117
response, err := s.HTTPRequest("GET", "/api/ready", nil)
118118
c.Assert(err, IsNil)
119119
c.Check(response.Code, Equals, 200)
120120
c.Check(response.Body.String(), Matches, "{\"Status\":\"Aptly is ready\"}")
121121
}
122122

123-
func (s *ApiSuite) TestGetHealthiness(c *C) {
123+
func (s *APISuite) TestGetHealthiness(c *C) {
124124
response, err := s.HTTPRequest("GET", "/api/healthy", nil)
125125
c.Assert(err, IsNil)
126126
c.Check(response.Code, Equals, 200)
127127
c.Check(response.Body.String(), Matches, "{\"Status\":\"Aptly is healthy\"}")
128128
}
129129

130-
func (s *ApiSuite) TestGetMetrics(c *C) {
130+
func (s *APISuite) TestGetMetrics(c *C) {
131131
response, err := s.HTTPRequest("GET", "/api/metrics", nil)
132132
c.Assert(err, IsNil)
133133
c.Check(response.Code, Equals, 200)
@@ -141,7 +141,7 @@ func (s *ApiSuite) TestGetMetrics(c *C) {
141141
c.Check(b, Matches, ".*aptly_build_info.*version=\"testVersion\".*")
142142
}
143143

144-
func (s *ApiSuite) TestRepoCreate(c *C) {
144+
func (s *APISuite) TestRepoCreate(c *C) {
145145
body, err := json.Marshal(gin.H{
146146
"Name": "dummy",
147147
})
@@ -150,7 +150,7 @@ func (s *ApiSuite) TestRepoCreate(c *C) {
150150
c.Assert(err, IsNil)
151151
}
152152

153-
func (s *ApiSuite) TestTruthy(c *C) {
153+
func (s *APISuite) TestTruthy(c *C) {
154154
c.Check(truthy("no"), Equals, false)
155155
c.Check(truthy("n"), Equals, false)
156156
c.Check(truthy("off"), Equals, false)

api/db.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// @Success 200 {object} string "Output"
2222
// @Failure 404 {object} Error "Not Found"
2323
// @Router /api/db/cleanup [post]
24-
func apiDbCleanup(c *gin.Context) {
24+
func apiDBCleanup(c *gin.Context) {
2525
resources := []string{string(task.AllResourcesKey)}
2626
maybeRunTaskInBackground(c, "Clean up db", resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
2727
var err error
@@ -109,8 +109,8 @@ func apiDbCleanup(c *gin.Context) {
109109

110110
if toDelete.Len() > 0 {
111111
batch := db.CreateBatch()
112-
toDelete.ForEach(func(ref []byte) error {
113-
collectionFactory.PackageCollection().DeleteByKey(ref, batch)
112+
_ = toDelete.ForEach(func(ref []byte) error {
113+
_ = collectionFactory.PackageCollection().DeleteByKey(ref, batch)
114114
return nil
115115
})
116116

api/files.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ func apiFilesUpload(c *gin.Context) {
122122
AbortWithJSONError(c, 500, err)
123123
return
124124
}
125-
defer src.Close()
125+
defer func() { _ = src.Close() }()
126126

127127
destPath := filepath.Join(path, filepath.Base(file.Filename))
128128
dst, err := os.Create(destPath)
129129
if err != nil {
130130
AbortWithJSONError(c, 500, err)
131131
return
132132
}
133-
defer dst.Close()
133+
defer func() { _ = dst.Close() }()
134134

135135
_, err = io.Copy(dst, src)
136136
if err != nil {

api/gpg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func apiGPGAddKey(c *gin.Context) {
6060
AbortWithJSONError(c, 400, err)
6161
return
6262
}
63-
defer os.RemoveAll(tempdir)
63+
defer func() { _ = os.RemoveAll(tempdir) }()
6464

6565
keypath := filepath.Join(tempdir, "key")
6666
keyfile, e := os.Create(keypath)

0 commit comments

Comments
 (0)