Skip to content

Commit 91013c1

Browse files
authored
chore: apply various modernisations (#531)
* Use any instead of interface{} given Go > 1.18 * Minor tidies thanks to gofumpt * Run "go fix ./..." on the codebase * Apply a few modernisations suggested by gopls check * Remove unused parameter suggested by gopls check
1 parent efb626b commit 91013c1

31 files changed

+50
-68
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
6868
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
6969
defer cancel()
7070

71-
var v interface{}
71+
var v any
7272
err = wsjson.Read(ctx, c, &v)
7373
if err != nil {
7474
// ...

accept.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !js
2-
// +build !js
32

43
package websocket
54

accept_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !js
2-
// +build !js
32

43
package websocket
54

autobahn_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !js
2-
// +build !js
32

43
package websocket_test
54

@@ -130,7 +129,7 @@ func wstestServer(tb testing.TB, ctx context.Context) (url string, closeFn func(
130129
url = "ws://" + serverAddr
131130
const outDir = "ci/out/autobahn-report"
132131

133-
specFile, err := tempJSONFile(map[string]interface{}{
132+
specFile, err := tempJSONFile(map[string]any{
134133
"url": url,
135134
"outdir": outDir,
136135
"cases": autobahnCases,
@@ -280,7 +279,7 @@ func unusedListenAddr() (_ string, err error) {
280279
return l.Addr().String(), nil
281280
}
282281

283-
func tempJSONFile(v interface{}) (string, error) {
282+
func tempJSONFile(v any) (string, error) {
284283
f, err := os.CreateTemp("", "temp.json")
285284
if err != nil {
286285
return "", fmt.Errorf("temp file: %w", err)

close.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !js
2-
// +build !js
32

43
package websocket
54

close_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !js
2-
// +build !js
32

43
package websocket
54

compress.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !js
2-
// +build !js
32

43
package websocket
54

@@ -168,8 +167,10 @@ type slidingWindow struct {
168167
buf []byte
169168
}
170169

171-
var swPoolMu sync.RWMutex
172-
var swPool = map[int]*sync.Pool{}
170+
var (
171+
swPoolMu sync.RWMutex
172+
swPool = map[int]*sync.Pool{}
173+
)
173174

174175
func slidingWindowPool(n int) *sync.Pool {
175176
swPoolMu.RLock()

compress_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !js
2-
// +build !js
32

43
package websocket
54

@@ -19,7 +18,7 @@ func Test_slidingWindow(t *testing.T) {
1918

2019
const testCount = 99
2120
const maxWindow = 99999
22-
for i := 0; i < testCount; i++ {
21+
for range testCount {
2322
t.Run("", func(t *testing.T) {
2423
t.Parallel()
2524

conn.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !js
2-
// +build !js
32

43
package websocket
54

conn_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestConn(t *testing.T) {
3636
return websocket.CompressionMode(xrand.Int(int(websocket.CompressionContextTakeover) + 1))
3737
}
3838

39-
for i := 0; i < 5; i++ {
39+
for range 5 {
4040
t.Run("", func(t *testing.T) {
4141
tt, c1, c2 := newConnTest(t, &websocket.DialOptions{
4242
CompressionMode: compressionMode(),
@@ -50,7 +50,7 @@ func TestConn(t *testing.T) {
5050

5151
c1.SetReadLimit(131072)
5252

53-
for i := 0; i < 5; i++ {
53+
for range 5 {
5454
err := wstest.Echo(tt.ctx, c1, 131072)
5555
assert.Success(t, err)
5656
}
@@ -76,7 +76,7 @@ func TestConn(t *testing.T) {
7676
c1.CloseRead(tt.ctx)
7777
c2.CloseRead(tt.ctx)
7878

79-
for i := 0; i < 10; i++ {
79+
for range 10 {
8080
err := c1.Ping(tt.ctx)
8181
assert.Success(t, err)
8282
}
@@ -185,7 +185,7 @@ func TestConn(t *testing.T) {
185185
const count = 100
186186
errs := make(chan error, count)
187187

188-
for i := 0; i < count; i++ {
188+
for range count {
189189
go func() {
190190
select {
191191
case errs <- c1.Write(tt.ctx, websocket.MessageBinary, msg):
@@ -195,7 +195,7 @@ func TestConn(t *testing.T) {
195195
}()
196196
}
197197

198-
for i := 0; i < count; i++ {
198+
for range count {
199199
select {
200200
case err := <-errs:
201201
assert.Success(t, err)
@@ -341,7 +341,7 @@ func TestConn(t *testing.T) {
341341
return wsjson.Write(tt.ctx, c1, exp)
342342
})
343343

344-
var act interface{}
344+
var act any
345345
err := wsjson.Read(tt.ctx, c1, &act)
346346
assert.Success(t, err)
347347
assert.Equal(t, "read msg", exp, act)
@@ -372,7 +372,7 @@ func TestConn(t *testing.T) {
372372
return wsjson.Write(tt.ctx, c1, exp)
373373
})
374374

375-
var act interface{}
375+
var act any
376376
err := wsjson.Read(tt.ctx, c1, &act)
377377
assert.Success(t, err)
378378
assert.Equal(t, "read msg", exp, act)
@@ -408,7 +408,7 @@ func TestConn(t *testing.T) {
408408

409409
c1.SetReadLimit(131072)
410410

411-
for i := 0; i < 5; i++ {
411+
for range 5 {
412412
err := wstest.Echo(tt.ctx, c1, 131072)
413413
assert.Success(t, err)
414414
}
@@ -660,7 +660,7 @@ func assertEcho(tb testing.TB, ctx context.Context, c *websocket.Conn) {
660660
return wsjson.Write(ctx, c, exp)
661661
})
662662

663-
var act interface{}
663+
var act any
664664
c.SetReadLimit(1 << 30)
665665
err := wsjson.Read(ctx, c, &act)
666666
assert.Success(tb, err)
@@ -682,7 +682,7 @@ func assertClose(tb testing.TB, c *websocket.Conn) {
682682

683683
func TestConcurrentClosePing(t *testing.T) {
684684
t.Parallel()
685-
for i := 0; i < 64; i++ {
685+
for range 64 {
686686
func() {
687687
c1, c2 := wstest.Pipe(nil, nil)
688688
defer c1.CloseNow()

0 commit comments

Comments
 (0)