Skip to content

Commit

Permalink
Merge pull request #664 from ably/fix/deprecated-ioutil
Browse files Browse the repository at this point in the history
Removed use of deprecated ioutil
  • Loading branch information
sacOO7 authored Sep 3, 2024
2 parents 673864c + f8a27da commit 8b38951
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 19 deletions.
5 changes: 2 additions & 3 deletions ably/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"mime"
"net/http"
"net/url"
Expand Down Expand Up @@ -443,7 +442,7 @@ func (a *Auth) requestAuthURL(ctx context.Context, params *TokenParams, opts *au
case "POST":
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Content-Length", strconv.Itoa(len(query)))
req.Body = ioutil.NopCloser(strings.NewReader(query))
req.Body = io.NopCloser(strings.NewReader(query))
default:
return nil, a.newError(40500, nil)
}
Expand All @@ -461,7 +460,7 @@ func (a *Auth) requestAuthURL(ctx context.Context, params *TokenParams, opts *au
}
switch typ {
case "text/plain":
token, err := ioutil.ReadAll(resp.Body)
token, err := io.ReadAll(resp.Body)
if err != nil {
return nil, a.newError(40000, err)
}
Expand Down
4 changes: 2 additions & 2 deletions ably/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ably
import (
"errors"
"fmt"
"io/ioutil"
"io"
"mime"
"net"
"net/http"
Expand Down Expand Up @@ -140,7 +140,7 @@ func statusCode(err error) int {
}

func errFromUnprocessableBody(resp *http.Response) error {
errMsg, err := ioutil.ReadAll(resp.Body)
errMsg, err := io.ReadAll(resp.Body)
if err == nil {
err = errors.New(string(errMsg))
}
Expand Down
7 changes: 3 additions & 4 deletions ably/rest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"mime"
"net/http"
Expand Down Expand Up @@ -837,13 +836,13 @@ func decode(typ string, r io.Reader, out interface{}) error {
case "application/json":
return json.NewDecoder(r).Decode(out)
case "application/x-msgpack":
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return err
}
return ablyutil.UnmarshalMsgpack(b, out)
case "text/plain":
p, err := ioutil.ReadAll(r)
p, err := io.ReadAll(r)
if err != nil {
return err
}
Expand All @@ -860,7 +859,7 @@ func decodeResp(resp *http.Response, out interface{}) error {
if err != nil {
return err
}
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)

return decode(typ, bytes.NewReader(b), out)
}
Expand Down
6 changes: 3 additions & 3 deletions ably/rest_client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestRestClient(t *testing.T) {
mockBody := []byte("{}")
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var err error
buffer, err = ioutil.ReadAll(r.Body)
buffer, err = io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestRestClient(t *testing.T) {
mockBody := []byte{0x80}
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var err error
buffer, err = ioutil.ReadAll(r.Body)
buffer, err = io.ReadAll(r.Body)
assert.NoError(t, err)
w.Header().Set("Content-Type", mockType)
w.WriteHeader(200)
Expand Down
3 changes: 1 addition & 2 deletions ablytest/proxies.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"errors"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -47,7 +46,7 @@ func Query(req *http.Request) (url.Values, error) {
case "GET":
return req.URL.Query(), nil
case "POST":
p, err := ioutil.ReadAll(req.Body)
p, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions ablytest/recorders.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"net/http"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -105,7 +104,7 @@ func (rec *RoundTripRecorder) Reset() {
func (rec *RoundTripRecorder) roundTrip(req *http.Request) (*http.Response, error) {
var buf bytes.Buffer
if req.Body != nil {
req.Body = ioutil.NopCloser(io.TeeReader(req.Body, &buf))
req.Body = io.NopCloser(io.TeeReader(req.Body, &buf))
}
resp, err := rec.Transport.RoundTrip(req)
req.Body = body(buf.Bytes())
Expand Down Expand Up @@ -253,5 +252,5 @@ func (c realtimeIOCloser) Close() error {
}

func body(p []byte) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader(p))
return io.NopCloser(bytes.NewReader(p))
}
4 changes: 2 additions & 2 deletions ablytest/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -177,7 +177,7 @@ func NewSandboxWithEnv(config *Config, env string) (*Sandbox, error) {
defer resp.Body.Close()
if resp.StatusCode > 299 {
err := errors.New(http.StatusText(resp.StatusCode))
if p, e := ioutil.ReadAll(resp.Body); e == nil && len(p) != 0 {
if p, e := io.ReadAll(resp.Body); e == nil && len(p) != 0 {
err = fmt.Errorf("request error: %s (%q)", err, p)
}
return nil, err
Expand Down

0 comments on commit 8b38951

Please sign in to comment.