Skip to content

Commit d88a86d

Browse files
committed
Apply a few modernisations suggested by gopls check
1 parent 0b61cfb commit d88a86d

File tree

8 files changed

+16
-19
lines changed

8 files changed

+16
-19
lines changed

compress_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Test_slidingWindow(t *testing.T) {
1818

1919
const testCount = 99
2020
const maxWindow = 99999
21-
for i := 0; i < testCount; i++ {
21+
for range testCount {
2222
t.Run("", func(t *testing.T) {
2323
t.Parallel()
2424

conn_test.go

Lines changed: 7 additions & 7 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)
@@ -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
}
@@ -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()

dial_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"crypto/rand"
99
"io"
10+
"maps"
1011
"net/http"
1112
"net/http/httptest"
1213
"net/url"
@@ -355,11 +356,10 @@ func (fc *forwardProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
355356
}
356357
defer resp.Body.Close()
357358

358-
for k, v := range resp.Header {
359-
w.Header()[k] = v
360-
}
359+
maps.Copy(w.Header(), resp.Header)
361360
w.Header().Set("PROXIED", "true")
362361
w.WriteHeader(resp.StatusCode)
362+
363363
if resprw, ok := resp.Body.(io.ReadWriter); ok {
364364
c, brw, err := w.(http.Hijacker).Hijack()
365365
if err != nil {

example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func ExampleConn_Ping() {
150150
// Required to read the Pongs from the server.
151151
ctx = c.CloseRead(ctx)
152152

153-
for i := 0; i < 5; i++ {
153+
for range 5 {
154154
err = c.Ping(ctx)
155155
if err != nil {
156156
log.Fatal(err)

frame_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestHeader(t *testing.T) {
5353
return r.Intn(2) == 0
5454
}
5555

56-
for i := 0; i < 10000; i++ {
56+
for range 10000 {
5757
h := header{
5858
fin: randBool(),
5959
rsv1: randBool(),

mask_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestMask(t *testing.T) {
4040
func testMask(t *testing.T, name string, fn func(b []byte, key uint32) uint32) {
4141
t.Run(name, func(t *testing.T) {
4242
t.Parallel()
43-
for i := 0; i < 9999; i++ {
43+
for range 9999 {
4444
keyb := make([]byte, 4)
4545
_, err := rand.Read(keyb)
4646
assert.Success(t, err)

write.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,7 @@ func (c *Conn) writeFramePayload(p []byte) (n int, err error) {
350350
// Start of next write in the buffer.
351351
i := c.bw.Buffered()
352352

353-
j := len(p)
354-
if j > c.bw.Available() {
355-
j = c.bw.Available()
356-
}
353+
j := min(len(p), c.bw.Available())
357354

358355
_, err := c.bw.Write(p[:j])
359356
if err != nil {

ws_js_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestWasm(t *testing.T) {
2828
assert.Equal(t, "response code", http.StatusSwitchingProtocols, resp.StatusCode)
2929

3030
c.SetReadLimit(65536)
31-
for i := 0; i < 10; i++ {
31+
for range 10 {
3232
err = wstest.Echo(ctx, c, 65536)
3333
assert.Success(t, err)
3434
}

0 commit comments

Comments
 (0)