Skip to content

Commit 8b38951

Browse files
authored
Merge pull request #664 from ably/fix/deprecated-ioutil
Removed use of deprecated ioutil
2 parents 673864c + f8a27da commit 8b38951

7 files changed

+15
-19
lines changed

ably/auth.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"mime"
1211
"net/http"
1312
"net/url"
@@ -443,7 +442,7 @@ func (a *Auth) requestAuthURL(ctx context.Context, params *TokenParams, opts *au
443442
case "POST":
444443
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
445444
req.Header.Set("Content-Length", strconv.Itoa(len(query)))
446-
req.Body = ioutil.NopCloser(strings.NewReader(query))
445+
req.Body = io.NopCloser(strings.NewReader(query))
447446
default:
448447
return nil, a.newError(40500, nil)
449448
}
@@ -461,7 +460,7 @@ func (a *Auth) requestAuthURL(ctx context.Context, params *TokenParams, opts *au
461460
}
462461
switch typ {
463462
case "text/plain":
464-
token, err := ioutil.ReadAll(resp.Body)
463+
token, err := io.ReadAll(resp.Body)
465464
if err != nil {
466465
return nil, a.newError(40000, err)
467466
}

ably/error.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package ably
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"mime"
88
"net"
99
"net/http"
@@ -140,7 +140,7 @@ func statusCode(err error) int {
140140
}
141141

142142
func errFromUnprocessableBody(resp *http.Response) error {
143-
errMsg, err := ioutil.ReadAll(resp.Body)
143+
errMsg, err := io.ReadAll(resp.Body)
144144
if err == nil {
145145
err = errors.New(string(errMsg))
146146
}

ably/rest_client.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/json"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"math/rand"
1312
"mime"
1413
"net/http"
@@ -837,13 +836,13 @@ func decode(typ string, r io.Reader, out interface{}) error {
837836
case "application/json":
838837
return json.NewDecoder(r).Decode(out)
839838
case "application/x-msgpack":
840-
b, err := ioutil.ReadAll(r)
839+
b, err := io.ReadAll(r)
841840
if err != nil {
842841
return err
843842
}
844843
return ablyutil.UnmarshalMsgpack(b, out)
845844
case "text/plain":
846-
p, err := ioutil.ReadAll(r)
845+
p, err := io.ReadAll(r)
847846
if err != nil {
848847
return err
849848
}
@@ -860,7 +859,7 @@ func decodeResp(resp *http.Response, out interface{}) error {
860859
if err != nil {
861860
return err
862861
}
863-
b, _ := ioutil.ReadAll(resp.Body)
862+
b, _ := io.ReadAll(resp.Body)
864863

865864
return decode(typ, bytes.NewReader(b), out)
866865
}

ably/rest_client_integration_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"encoding/json"
1111
"errors"
1212
"fmt"
13-
"io/ioutil"
13+
"io"
1414
"net"
1515
"net/http"
1616
"net/http/httptest"
@@ -48,7 +48,7 @@ func TestRestClient(t *testing.T) {
4848
mockBody := []byte("{}")
4949
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
5050
var err error
51-
buffer, err = ioutil.ReadAll(r.Body)
51+
buffer, err = io.ReadAll(r.Body)
5252
if err != nil {
5353
t.Fatal(err)
5454
}
@@ -77,7 +77,7 @@ func TestRestClient(t *testing.T) {
7777
mockBody := []byte{0x80}
7878
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
7979
var err error
80-
buffer, err = ioutil.ReadAll(r.Body)
80+
buffer, err = io.ReadAll(r.Body)
8181
assert.NoError(t, err)
8282
w.Header().Set("Content-Type", mockType)
8383
w.WriteHeader(200)

ablytest/proxies.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"errors"
77
"io"
8-
"io/ioutil"
98
"net"
109
"net/http"
1110
"net/url"
@@ -47,7 +46,7 @@ func Query(req *http.Request) (url.Values, error) {
4746
case "GET":
4847
return req.URL.Query(), nil
4948
case "POST":
50-
p, err := ioutil.ReadAll(req.Body)
49+
p, err := io.ReadAll(req.Body)
5150
if err != nil {
5251
return nil, err
5352
}

ablytest/recorders.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66
"io"
7-
"io/ioutil"
87
"net/http"
98
"sync"
109
"sync/atomic"
@@ -105,7 +104,7 @@ func (rec *RoundTripRecorder) Reset() {
105104
func (rec *RoundTripRecorder) roundTrip(req *http.Request) (*http.Response, error) {
106105
var buf bytes.Buffer
107106
if req.Body != nil {
108-
req.Body = ioutil.NopCloser(io.TeeReader(req.Body, &buf))
107+
req.Body = io.NopCloser(io.TeeReader(req.Body, &buf))
109108
}
110109
resp, err := rec.Transport.RoundTrip(req)
111110
req.Body = body(buf.Bytes())
@@ -253,5 +252,5 @@ func (c realtimeIOCloser) Close() error {
253252
}
254253

255254
func body(p []byte) io.ReadCloser {
256-
return ioutil.NopCloser(bytes.NewReader(p))
255+
return io.NopCloser(bytes.NewReader(p))
257256
}

ablytest/sandbox.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"log"
1111
"net"
1212
"net/http"
@@ -177,7 +177,7 @@ func NewSandboxWithEnv(config *Config, env string) (*Sandbox, error) {
177177
defer resp.Body.Close()
178178
if resp.StatusCode > 299 {
179179
err := errors.New(http.StatusText(resp.StatusCode))
180-
if p, e := ioutil.ReadAll(resp.Body); e == nil && len(p) != 0 {
180+
if p, e := io.ReadAll(resp.Body); e == nil && len(p) != 0 {
181181
err = fmt.Errorf("request error: %s (%q)", err, p)
182182
}
183183
return nil, err

0 commit comments

Comments
 (0)