Skip to content

Migrate from deprecated io/ioutil #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions autobahn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -146,7 +146,7 @@ func wstestCaseCount(ctx context.Context, url string) (cases int, err error) {
if err != nil {
return 0, err
}
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return 0, err
}
Expand All @@ -161,7 +161,7 @@ func wstestCaseCount(ctx context.Context, url string) (cases int, err error) {
}

func checkWSTestIndex(t *testing.T, path string) {
wstestOut, err := ioutil.ReadFile(path)
wstestOut, err := os.ReadFile(path)
assert.Success(t, err)

var indexJSON map[string]map[string]struct {
Expand Down Expand Up @@ -206,7 +206,7 @@ func unusedListenAddr() (_ string, err error) {
}

func tempJSONFile(v interface{}) (string, error) {
f, err := ioutil.TempFile("", "temp.json")
f, err := os.CreateTemp("", "temp.json")
if err != nil {
return "", fmt.Errorf("temp file: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -174,7 +173,7 @@ func TestConn(t *testing.T) {
return n2.Close()
})

b, err := ioutil.ReadAll(n1)
b, err := io.ReadAll(n1)
assert.Success(t, err)

_, err = n1.Read(nil)
Expand Down Expand Up @@ -205,7 +204,7 @@ func TestConn(t *testing.T) {
return nil
})

_, err := ioutil.ReadAll(n1)
_, err := io.ReadAll(n1)
assert.Contains(t, err, `unexpected frame type read (expected MessageBinary): MessageText`)

select {
Expand Down
5 changes: 2 additions & 3 deletions dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -114,9 +113,9 @@ func dial(ctx context.Context, urls string, opts *DialOptions, rand io.Reader) (
})
defer timer.Stop()

b, _ := ioutil.ReadAll(r)
b, _ := io.ReadAll(r)
respBody.Close()
resp.Body = ioutil.NopCloser(bytes.NewReader(b))
resp.Body = io.NopCloser(bytes.NewReader(b))
}
}()

Expand Down
5 changes: 2 additions & 3 deletions dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"crypto/rand"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -75,7 +74,7 @@ func TestBadDials(t *testing.T) {
_, _, err := Dial(ctx, "ws://example.com", &DialOptions{
HTTPClient: mockHTTPClient(func(*http.Request) (*http.Response, error) {
return &http.Response{
Body: ioutil.NopCloser(strings.NewReader("hi")),
Body: io.NopCloser(strings.NewReader("hi")),
}, nil
}),
})
Expand All @@ -97,7 +96,7 @@ func TestBadDials(t *testing.T) {
return &http.Response{
StatusCode: http.StatusSwitchingProtocols,
Header: h,
Body: ioutil.NopCloser(strings.NewReader("hi")),
Body: io.NopCloser(strings.NewReader("hi")),
}, nil
}

Expand Down
10 changes: 5 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
// More documentation at https://nhooyr.io/websocket.
//
// Wasm
// # Wasm
//
// The client side supports compiling to Wasm.
// It wraps the WebSocket browser API.
Expand All @@ -25,8 +25,8 @@
//
// Some important caveats to be aware of:
//
// - Accept always errors out
// - Conn.Ping is no-op
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
// - Accept always errors out
// - Conn.Ping is no-op
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
package websocket // import "nhooyr.io/websocket"
4 changes: 2 additions & 2 deletions examples/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"context"
"errors"
"io/ioutil"
"io"
"log"
"net/http"
"sync"
Expand Down Expand Up @@ -98,7 +98,7 @@ func (cs *chatServer) publishHandler(w http.ResponseWriter, r *http.Request) {
return
}
body := http.MaxBytesReader(w, r.Body, 8192)
msg, err := ioutil.ReadAll(body)
msg, err := io.ReadAll(body)
if err != nil {
http.Error(w, http.StatusText(http.StatusRequestEntityTooLarge), http.StatusRequestEntityTooLarge)
return
Expand Down
3 changes: 1 addition & 2 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"strings"
"time"

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

b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
return typ, b, err
}

Expand Down