Skip to content

Commit 65fa7b7

Browse files
Acconutmarius
andauthored
Fixes from Go 1.26's go fix (#1346)
* Fixes from Go 1.26's `go fix` * Fix CI setup for Windows Without `shell: bash`, steps that run multiple commands will only fail if the last command has a non-zero exit code. See actions/runner-images#6668 * Upgrade to Go 1.25 --------- Co-authored-by: marius <marius@example.com>
1 parent d6e2497 commit 65fa7b7

File tree

14 files changed

+34
-44
lines changed

14 files changed

+34
-44
lines changed

.github/workflows/continuous-integration.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
name: Clean module files
3030
run: |
3131
go mod tidy
32+
shell: bash
3233

3334
-
3435
name: Set tusd output
@@ -58,6 +59,7 @@ jobs:
5859
run: |
5960
go vet ./pkg/...
6061
go vet ./internal/...
62+
shell: bash
6163

6264
pages:
6365
runs-on: ubuntu-latest

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ module github.com/tus/tusd/v2
22

33
// Specify the Go version needed for the Heroku deployment
44
// See https://github.com/heroku/heroku-buildpack-go#go-module-specifics
5-
// +heroku goVersion go1.24
6-
go 1.24.0
5+
// +heroku goVersion go1.25
6+
go 1.25
77

8-
toolchain go1.24.1
8+
toolchain go1.25.0
99

1010
require (
1111
cloud.google.com/go/storage v1.59.2

pkg/filestore/filestore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func TestConcatUploads(t *testing.T) {
202202
"def",
203203
"ghi",
204204
}
205-
for i := 0; i < 3; i++ {
205+
for i := range 3 {
206206
upload, err := store.NewUpload(ctx, handler.FileInfo{Size: 3})
207207
a.NoError(err)
208208

pkg/gcsstore/gcsservice.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (service *GCSService) compose(ctx context.Context, bucket string, srcs []st
145145
}
146146
objSrcs := make([]*storage.ObjectHandle, len(srcs))
147147
var crc uint32
148-
for i := 0; i < len(srcs); i++ {
148+
for i := range srcs {
149149
objSrcs[i] = service.Client.Bucket(bucket).Object(srcs[i])
150150
srcAttrs, err := service.GetObjectAttrs(ctx, GCSObjectParams{
151151
Bucket: bucket,
@@ -170,7 +170,7 @@ func (service *GCSService) compose(ctx context.Context, bucket string, srcs []st
170170
return err
171171
}
172172

173-
for i := 0; i < COMPOSE_RETRIES; i++ {
173+
for range COMPOSE_RETRIES {
174174
dstCRC, err := service.ComposeFrom(ctx, objSrcs, dstParams, attrs.ContentType)
175175
if err != nil {
176176
return err
@@ -223,7 +223,7 @@ func (service *GCSService) recursiveCompose(ctx context.Context, srcs []string,
223223
tmpSrcLen := int(math.Ceil(float64(len(srcs)) / float64(MAX_OBJECT_COMPOSITION)))
224224
tmpSrcs := make([]string, tmpSrcLen)
225225

226-
for i := 0; i < tmpSrcLen; i++ {
226+
for i := range tmpSrcLen {
227227
start := i * MAX_OBJECT_COMPOSITION
228228
end := MAX_OBJECT_COMPOSITION * (i + 1)
229229
if tmpSrcLen-i == 1 {

pkg/handler/context_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type contextValueMatcher struct {
2020
expectedValue any
2121
}
2222

23-
func (m contextValueMatcher) Matches(a interface{}) bool {
23+
func (m contextValueMatcher) Matches(a any) bool {
2424
ctx, ok := a.(context.Context)
2525
if !ok {
2626
return false
@@ -41,7 +41,7 @@ type contextCancelMatcher struct {
4141
maxDelay time.Duration
4242
}
4343

44-
func (m contextCancelMatcher) Matches(a interface{}) bool {
44+
func (m contextCancelMatcher) Matches(a any) bool {
4545
ctx, ok := a.(context.Context)
4646
if !ok {
4747
return false

pkg/handler/hooks_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,23 @@ func TestHookEventHeaderRace(t *testing.T) {
3737

3838
// Goroutine 1: Simulate async hook processing (JSON encoding)
3939
// This is what happens in invokeHookAsync -> json.Marshal
40-
wg.Add(1)
41-
go func() {
42-
defer wg.Done()
40+
wg.Go(func() {
4341
for range iterations {
4442
// This iterates over the Header map
4543
_, _ = json.Marshal(event.HTTPRequest)
4644
}
47-
}()
45+
})
4846

4947
// Goroutine 2: Simulate concurrent request header modification
5048
// This could happen if another hook event is created for the same request
5149
// or if middleware modifies headers
52-
wg.Add(1)
53-
go func() {
54-
defer wg.Done()
50+
wg.Go(func() {
5551
for range iterations {
5652
// This writes to the Header map
5753
c.req.Header.Set("X-Request-ID", "some-value")
5854
c.req.Header.Del("X-Request-ID")
5955
}
60-
}()
56+
})
6157

6258
wg.Wait()
6359
}

pkg/handler/http.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package handler
22

33
import (
4+
"maps"
45
"net/http"
56
"strconv"
67
)
@@ -67,13 +68,9 @@ func (resp1 HTTPResponse) MergeWith(resp2 HTTPResponse) HTTPResponse {
6768
// into the header map from response 1.
6869
newResp.Header = make(HTTPHeader, len(resp1.Header)+len(resp2.Header))
6970

70-
for key, value := range resp1.Header {
71-
newResp.Header[key] = value
72-
}
71+
maps.Copy(newResp.Header, resp1.Header)
7372

74-
for key, value := range resp2.Header {
75-
newResp.Header[key] = value
76-
}
73+
maps.Copy(newResp.Header, resp2.Header)
7774

7875
return newResp
7976
}

pkg/handler/metrics.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package handler
22

33
import (
4+
"maps"
45
"sync"
56
"sync/atomic"
67
)
@@ -123,9 +124,7 @@ func (e *ErrorsTotalMap) retrievePointerFor(err Error) *uint64 {
123124
func (e *ErrorsTotalMap) Load() map[ErrorsTotalMapEntry]*uint64 {
124125
m := make(map[ErrorsTotalMapEntry]*uint64, len(e.counter))
125126
e.lock.RLock()
126-
for err, ptr := range e.counter {
127-
m[err] = ptr
128-
}
127+
maps.Copy(m, e.counter)
129128
e.lock.RUnlock()
130129

131130
return m

pkg/handler/unrouted_handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ func getIETFDraftUploadLength(r *http.Request) (length int64, lengthIsDeferred b
15801580
func ParseMetadataHeader(header string) map[string]string {
15811581
meta := make(map[string]string)
15821582

1583-
for _, element := range strings.Split(header, ",") {
1583+
for element := range strings.SplitSeq(header, ",") {
15841584
element := strings.TrimSpace(element)
15851585

15861586
parts := strings.Split(element, " ")
@@ -1646,8 +1646,8 @@ func parseConcat(header string, basePath string) (isPartial bool, isFinal bool,
16461646
if strings.HasPrefix(header, "final;") && len(header) > l {
16471647
isFinal = true
16481648

1649-
list := strings.Split(header[l:], " ")
1650-
for _, value := range list {
1649+
list := strings.SplitSeq(header[l:], " ")
1650+
for value := range list {
16511651
value := strings.TrimSpace(value)
16521652
if value == "" {
16531653
continue

pkg/handler/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func NewReaderMatcher(expect string) gomock.Matcher {
109109
}
110110
}
111111

112-
func (m readerMatcher) Matches(x interface{}) bool {
112+
func (m readerMatcher) Matches(x any) bool {
113113
input, ok := x.(io.Reader)
114114
if !ok {
115115
return false

0 commit comments

Comments
 (0)