Skip to content

Commit ede9ffd

Browse files
committed
Replace ioutil with io
`ioutil` is deprecated, and on all the versions of Go we support, its functionality is replaced with `io`.
1 parent 2c76491 commit ede9ffd

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

fclient/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"crypto/tls"
2222
"encoding/json"
2323
"fmt"
24-
"io/ioutil"
24+
"io"
2525
"net"
2626
"net/http"
2727
"net/url"
@@ -350,7 +350,7 @@ func (fc *Client) LookupUserInfo(
350350
}
351351
if response.StatusCode < 200 || response.StatusCode >= 300 {
352352
var errorOutput []byte
353-
errorOutput, err = ioutil.ReadAll(response.Body)
353+
errorOutput, err = io.ReadAll(response.Body)
354354
if err != nil {
355355
return
356356
}
@@ -525,7 +525,7 @@ func (fc *Client) DoRequestAndParseResponse(
525525
if response.StatusCode/100 != 2 { // not 2xx
526526
// Adapted from https://github.com/matrix-org/gomatrix/blob/master/client.go
527527
var contents []byte
528-
contents, err = ioutil.ReadAll(response.Body)
528+
contents, err = io.ReadAll(response.Body)
529529
if err != nil {
530530
return err
531531
}

fclient/federationclient_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"reflect"
1111
"strings"
@@ -63,7 +63,7 @@ func TestSendJoinFallback(t *testing.T) {
6363
if strings.HasPrefix(req.URL.Path, "/_matrix/federation/v2/send_join") {
6464
return &http.Response{
6565
StatusCode: 404,
66-
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
66+
Body: io.NopCloser(strings.NewReader("404 not found")),
6767
}, nil
6868
}
6969
if !strings.HasPrefix(req.URL.Path, "/_matrix/federation/v1/send_join") {
@@ -72,7 +72,7 @@ func TestSendJoinFallback(t *testing.T) {
7272
t.Logf("Sending response: %s", string(v1ResBytes))
7373
return &http.Response{
7474
StatusCode: 200,
75-
Body: ioutil.NopCloser(bytes.NewReader(v1ResBytes)),
75+
Body: io.NopCloser(bytes.NewReader(v1ResBytes)),
7676
}, nil
7777
},
7878
},
@@ -126,12 +126,12 @@ func TestSendJoinJSON(t *testing.T) {
126126
t.Logf("Sending response: %s", string(respSendJoinResponseJSON))
127127
return &http.Response{
128128
StatusCode: 200,
129-
Body: ioutil.NopCloser(bytes.NewReader(respSendJoinResponseJSON)),
129+
Body: io.NopCloser(bytes.NewReader(respSendJoinResponseJSON)),
130130
}, nil
131131
}
132132
return &http.Response{
133133
StatusCode: 404,
134-
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
134+
Body: io.NopCloser(strings.NewReader("404 not found")),
135135
}, nil
136136
},
137137
},
@@ -185,12 +185,12 @@ func TestSendTransactionToRelay(t *testing.T) {
185185
if strings.HasPrefix(req.URL.Path, "/_matrix/federation/v1/send_relay") {
186186
return &http.Response{
187187
StatusCode: 200,
188-
Body: ioutil.NopCloser(bytes.NewReader(respSendResponseJSON)),
188+
Body: io.NopCloser(bytes.NewReader(respSendResponseJSON)),
189189
}, nil
190190
}
191191
return &http.Response{
192192
StatusCode: 404,
193-
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
193+
Body: io.NopCloser(strings.NewReader("404 not found")),
194194
}, nil
195195
},
196196
},
@@ -232,12 +232,12 @@ func TestSendTransactionToRelayReportsFailure(t *testing.T) {
232232
if strings.HasPrefix(req.URL.Path, "/_matrix/federation/v1/send_relay") {
233233
return &http.Response{
234234
StatusCode: 400,
235-
Body: ioutil.NopCloser(bytes.NewReader(respSendResponseJSON)),
235+
Body: io.NopCloser(bytes.NewReader(respSendResponseJSON)),
236236
}, nil
237237
}
238238
return &http.Response{
239239
StatusCode: 404,
240-
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
240+
Body: io.NopCloser(strings.NewReader("404 not found")),
241241
}, nil
242242
},
243243
},

fclient/request.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"mime"
109
"net/http"
1110
"strings"
@@ -274,7 +273,7 @@ func readHTTPRequest(req *http.Request) (*FederationRequest, error) { // nolint:
274273
result.fields.Method = req.Method
275274
result.fields.RequestURI = req.URL.RequestURI()
276275

277-
content, err := ioutil.ReadAll(req.Body)
276+
content, err := io.ReadAll(req.Body)
278277
if err != nil {
279278
return nil, err
280279
}

0 commit comments

Comments
 (0)