Skip to content

Commit 91423a9

Browse files
authored
Merge pull request #371 from keystroke3/master
Migrate from deprecated `io/ioutil`
2 parents 75bf907 + e2bb5be commit 91423a9

File tree

6 files changed

+13
-17
lines changed

6 files changed

+13
-17
lines changed

autobahn_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"context"
88
"encoding/json"
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"net"
1212
"os"
1313
"os/exec"
@@ -202,7 +202,7 @@ func wstestCaseCount(ctx context.Context, url string) (cases int, err error) {
202202
if err != nil {
203203
return 0, err
204204
}
205-
b, err := ioutil.ReadAll(r)
205+
b, err := io.ReadAll(r)
206206
if err != nil {
207207
return 0, err
208208
}
@@ -217,7 +217,7 @@ func wstestCaseCount(ctx context.Context, url string) (cases int, err error) {
217217
}
218218

219219
func checkWSTestIndex(t *testing.T, path string) {
220-
wstestOut, err := ioutil.ReadFile(path)
220+
wstestOut, err := os.ReadFile(path)
221221
assert.Success(t, err)
222222

223223
var indexJSON map[string]map[string]struct {
@@ -262,7 +262,7 @@ func unusedListenAddr() (_ string, err error) {
262262
}
263263

264264
func tempJSONFile(v interface{}) (string, error) {
265-
f, err := ioutil.TempFile("", "temp.json")
265+
f, err := os.CreateTemp("", "temp.json")
266266
if err != nil {
267267
return "", fmt.Errorf("temp file: %w", err)
268268
}

conn_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"net/http"
1312
"net/http/httptest"
1413
"os"
@@ -170,7 +169,7 @@ func TestConn(t *testing.T) {
170169
return n2.Close()
171170
})
172171

173-
b, err := ioutil.ReadAll(n1)
172+
b, err := io.ReadAll(n1)
174173
assert.Success(t, err)
175174

176175
_, err = n1.Read(nil)
@@ -198,7 +197,7 @@ func TestConn(t *testing.T) {
198197
return err
199198
})
200199

201-
_, err := ioutil.ReadAll(n1)
200+
_, err := io.ReadAll(n1)
202201
assert.Contains(t, err, `unexpected frame type read (expected MessageBinary): MessageText`)
203202

204203
select {

dial.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"encoding/base64"
1212
"fmt"
1313
"io"
14-
"io/ioutil"
1514
"net/http"
1615
"net/url"
1716
"strings"
@@ -122,9 +121,9 @@ func dial(ctx context.Context, urls string, opts *DialOptions, rand io.Reader) (
122121
})
123122
defer timer.Stop()
124123

125-
b, _ := ioutil.ReadAll(r)
124+
b, _ := io.ReadAll(r)
126125
respBody.Close()
127-
resp.Body = ioutil.NopCloser(bytes.NewReader(b))
126+
resp.Body = io.NopCloser(bytes.NewReader(b))
128127
}
129128
}()
130129

dial_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"context"
88
"crypto/rand"
99
"io"
10-
"io/ioutil"
1110
"net/http"
1211
"net/http/httptest"
1312
"strings"
@@ -76,7 +75,7 @@ func TestBadDials(t *testing.T) {
7675
_, _, err := Dial(ctx, "ws://example.com", &DialOptions{
7776
HTTPClient: mockHTTPClient(func(*http.Request) (*http.Response, error) {
7877
return &http.Response{
79-
Body: ioutil.NopCloser(strings.NewReader("hi")),
78+
Body: io.NopCloser(strings.NewReader("hi")),
8079
}, nil
8180
}),
8281
})
@@ -98,7 +97,7 @@ func TestBadDials(t *testing.T) {
9897
return &http.Response{
9998
StatusCode: http.StatusSwitchingProtocols,
10099
Header: h,
101-
Body: ioutil.NopCloser(strings.NewReader("hi")),
100+
Body: io.NopCloser(strings.NewReader("hi")),
102101
}, nil
103102
}
104103

examples/chat/chat.go

Lines changed: 2 additions & 2 deletions
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

read.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"errors"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"strings"
1413
"time"
1514

@@ -44,7 +43,7 @@ func (c *Conn) Read(ctx context.Context) (MessageType, []byte, error) {
4443
return 0, nil, err
4544
}
4645

47-
b, err := ioutil.ReadAll(r)
46+
b, err := io.ReadAll(r)
4847
return typ, b, err
4948
}
5049

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy