Skip to content

Commit e2bb5be

Browse files
committed
Migrate from deprecated io/ioutil
1 parent 14fb98e commit e2bb5be

File tree

7 files changed

+18
-22
lines changed

7 files changed

+18
-22
lines changed

Diff for: autobahn_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"context"
77
"encoding/json"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"net"
1111
"os"
1212
"os/exec"
@@ -146,7 +146,7 @@ func wstestCaseCount(ctx context.Context, url string) (cases int, err error) {
146146
if err != nil {
147147
return 0, err
148148
}
149-
b, err := ioutil.ReadAll(r)
149+
b, err := io.ReadAll(r)
150150
if err != nil {
151151
return 0, err
152152
}
@@ -161,7 +161,7 @@ func wstestCaseCount(ctx context.Context, url string) (cases int, err error) {
161161
}
162162

163163
func checkWSTestIndex(t *testing.T, path string) {
164-
wstestOut, err := ioutil.ReadFile(path)
164+
wstestOut, err := os.ReadFile(path)
165165
assert.Success(t, err)
166166

167167
var indexJSON map[string]map[string]struct {
@@ -206,7 +206,7 @@ func unusedListenAddr() (_ string, err error) {
206206
}
207207

208208
func tempJSONFile(v interface{}) (string, error) {
209-
f, err := ioutil.TempFile("", "temp.json")
209+
f, err := os.CreateTemp("", "temp.json")
210210
if err != nil {
211211
return "", fmt.Errorf("temp file: %w", err)
212212
}

Diff for: conn_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"context"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"net/http"
1211
"net/http/httptest"
1312
"os"
@@ -174,7 +173,7 @@ func TestConn(t *testing.T) {
174173
return n2.Close()
175174
})
176175

177-
b, err := ioutil.ReadAll(n1)
176+
b, err := io.ReadAll(n1)
178177
assert.Success(t, err)
179178

180179
_, err = n1.Read(nil)
@@ -205,7 +204,7 @@ func TestConn(t *testing.T) {
205204
return nil
206205
})
207206

208-
_, err := ioutil.ReadAll(n1)
207+
_, err := io.ReadAll(n1)
209208
assert.Contains(t, err, `unexpected frame type read (expected MessageBinary): MessageText`)
210209

211210
select {

Diff for: dial.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"encoding/base64"
1111
"fmt"
1212
"io"
13-
"io/ioutil"
1413
"net/http"
1514
"net/url"
1615
"strings"
@@ -114,9 +113,9 @@ func dial(ctx context.Context, urls string, opts *DialOptions, rand io.Reader) (
114113
})
115114
defer timer.Stop()
116115

117-
b, _ := ioutil.ReadAll(r)
116+
b, _ := io.ReadAll(r)
118117
respBody.Close()
119-
resp.Body = ioutil.NopCloser(bytes.NewReader(b))
118+
resp.Body = io.NopCloser(bytes.NewReader(b))
120119
}
121120
}()
122121

Diff for: dial_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"context"
77
"crypto/rand"
88
"io"
9-
"io/ioutil"
109
"net/http"
1110
"net/http/httptest"
1211
"strings"
@@ -75,7 +74,7 @@ func TestBadDials(t *testing.T) {
7574
_, _, err := Dial(ctx, "ws://example.com", &DialOptions{
7675
HTTPClient: mockHTTPClient(func(*http.Request) (*http.Response, error) {
7776
return &http.Response{
78-
Body: ioutil.NopCloser(strings.NewReader("hi")),
77+
Body: io.NopCloser(strings.NewReader("hi")),
7978
}, nil
8079
}),
8180
})
@@ -97,7 +96,7 @@ func TestBadDials(t *testing.T) {
9796
return &http.Response{
9897
StatusCode: http.StatusSwitchingProtocols,
9998
Header: h,
100-
Body: ioutil.NopCloser(strings.NewReader("hi")),
99+
Body: io.NopCloser(strings.NewReader("hi")),
101100
}, nil
102101
}
103102

Diff for: doc.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//
1717
// More documentation at https://nhooyr.io/websocket.
1818
//
19-
// Wasm
19+
// # Wasm
2020
//
2121
// The client side supports compiling to Wasm.
2222
// It wraps the WebSocket browser API.
@@ -25,8 +25,8 @@
2525
//
2626
// Some important caveats to be aware of:
2727
//
28-
// - Accept always errors out
29-
// - Conn.Ping is no-op
30-
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
31-
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
28+
// - Accept always errors out
29+
// - Conn.Ping is no-op
30+
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
31+
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
3232
package websocket // import "nhooyr.io/websocket"

Diff for: examples/chat/chat.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"context"
55
"errors"
6-
"io/ioutil"
6+
"io"
77
"log"
88
"net/http"
99
"sync"
@@ -98,7 +98,7 @@ func (cs *chatServer) publishHandler(w http.ResponseWriter, r *http.Request) {
9898
return
9999
}
100100
body := http.MaxBytesReader(w, r.Body, 8192)
101-
msg, err := ioutil.ReadAll(body)
101+
msg, err := io.ReadAll(body)
102102
if err != nil {
103103
http.Error(w, http.StatusText(http.StatusRequestEntityTooLarge), http.StatusRequestEntityTooLarge)
104104
return

Diff for: read.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"errors"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"strings"
1312
"time"
1413

@@ -38,7 +37,7 @@ func (c *Conn) Read(ctx context.Context) (MessageType, []byte, error) {
3837
return 0, nil, err
3938
}
4039

41-
b, err := ioutil.ReadAll(r)
40+
b, err := io.ReadAll(r)
4241
return typ, b, err
4342
}
4443

0 commit comments

Comments
 (0)