aboutsummaryrefslogtreecommitdiff
path: root/clientapi
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-08-05 10:26:59 +0100
committerGitHub <noreply@github.com>2022-08-05 10:26:59 +0100
commitc8935fb53f122b367eda61ec7811c406193d29ba (patch)
tree928c78461943f180dde6b2b4e4cd1d26792248f1 /clientapi
parent1b7f84250a46b401eccb89acafdef1b379f2dbc0 (diff)
Do not use `ioutil` as it is deprecated (#2625)
Diffstat (limited to 'clientapi')
-rw-r--r--clientapi/auth/login.go3
-rw-r--r--clientapi/httputil/httputil.go6
-rw-r--r--clientapi/routing/account_data.go6
-rw-r--r--clientapi/routing/deactivate.go4
-rw-r--r--clientapi/routing/device.go4
-rw-r--r--clientapi/routing/register.go6
-rw-r--r--clientapi/routing/register_secret_test.go4
7 files changed, 16 insertions, 17 deletions
diff --git a/clientapi/auth/login.go b/clientapi/auth/login.go
index 5f51c662..5467e814 100644
--- a/clientapi/auth/login.go
+++ b/clientapi/auth/login.go
@@ -18,7 +18,6 @@ import (
"context"
"encoding/json"
"io"
- "io/ioutil"
"net/http"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
@@ -34,7 +33,7 @@ import (
// If the final return value is non-nil, an error occurred and the cleanup function
// is nil.
func LoginFromJSONReader(ctx context.Context, r io.Reader, useraccountAPI uapi.UserLoginAPI, userAPI UserInternalAPIForLogin, cfg *config.ClientAPI) (*Login, LoginCleanupFunc, *util.JSONResponse) {
- reqBytes, err := ioutil.ReadAll(r)
+ reqBytes, err := io.ReadAll(r)
if err != nil {
err := &util.JSONResponse{
Code: http.StatusBadRequest,
diff --git a/clientapi/httputil/httputil.go b/clientapi/httputil/httputil.go
index b4770136..74f84f1e 100644
--- a/clientapi/httputil/httputil.go
+++ b/clientapi/httputil/httputil.go
@@ -16,7 +16,7 @@ package httputil
import (
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"unicode/utf8"
@@ -29,9 +29,9 @@ import (
func UnmarshalJSONRequest(req *http.Request, iface interface{}) *util.JSONResponse {
// encoding/json allows invalid utf-8, matrix does not
// https://matrix.org/docs/spec/client_server/r0.6.1#api-standards
- body, err := ioutil.ReadAll(req.Body)
+ body, err := io.ReadAll(req.Body)
if err != nil {
- util.GetLogger(req.Context()).WithError(err).Error("ioutil.ReadAll failed")
+ util.GetLogger(req.Context()).WithError(err).Error("io.ReadAll failed")
resp := jsonerror.InternalServerError()
return &resp
}
diff --git a/clientapi/routing/account_data.go b/clientapi/routing/account_data.go
index 0d3a4949..b28f0bb1 100644
--- a/clientapi/routing/account_data.go
+++ b/clientapi/routing/account_data.go
@@ -17,7 +17,7 @@ package routing
import (
"encoding/json"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"github.com/matrix-org/dendrite/clientapi/httputil"
@@ -101,9 +101,9 @@ func SaveAccountData(
}
}
- body, err := ioutil.ReadAll(req.Body)
+ body, err := io.ReadAll(req.Body)
if err != nil {
- util.GetLogger(req.Context()).WithError(err).Error("ioutil.ReadAll failed")
+ util.GetLogger(req.Context()).WithError(err).Error("io.ReadAll failed")
return jsonerror.InternalServerError()
}
diff --git a/clientapi/routing/deactivate.go b/clientapi/routing/deactivate.go
index c8aa6a3b..f213db7f 100644
--- a/clientapi/routing/deactivate.go
+++ b/clientapi/routing/deactivate.go
@@ -1,7 +1,7 @@
package routing
import (
- "io/ioutil"
+ "io"
"net/http"
"github.com/matrix-org/dendrite/clientapi/auth"
@@ -20,7 +20,7 @@ func Deactivate(
) util.JSONResponse {
ctx := req.Context()
defer req.Body.Close() // nolint:errcheck
- bodyBytes, err := ioutil.ReadAll(req.Body)
+ bodyBytes, err := io.ReadAll(req.Body)
if err != nil {
return util.JSONResponse{
Code: http.StatusBadRequest,
diff --git a/clientapi/routing/device.go b/clientapi/routing/device.go
index bb1cf47b..e3a02661 100644
--- a/clientapi/routing/device.go
+++ b/clientapi/routing/device.go
@@ -15,7 +15,7 @@
package routing
import (
- "io/ioutil"
+ "io"
"net"
"net/http"
@@ -175,7 +175,7 @@ func DeleteDeviceById(
}()
ctx := req.Context()
defer req.Body.Close() // nolint:errcheck
- bodyBytes, err := ioutil.ReadAll(req.Body)
+ bodyBytes, err := io.ReadAll(req.Body)
if err != nil {
return util.JSONResponse{
Code: http.StatusBadRequest,
diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go
index c4ac0f2e..af0329a4 100644
--- a/clientapi/routing/register.go
+++ b/clientapi/routing/register.go
@@ -19,7 +19,7 @@ import (
"context"
"encoding/json"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"net/url"
"regexp"
@@ -371,7 +371,7 @@ func validateRecaptcha(
// Grab the body of the response from the captcha server
var r recaptchaResponse
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
if err != nil {
return &util.JSONResponse{
Code: http.StatusGatewayTimeout,
@@ -539,7 +539,7 @@ func Register(
cfg *config.ClientAPI,
) util.JSONResponse {
defer req.Body.Close() // nolint: errcheck
- reqBody, err := ioutil.ReadAll(req.Body)
+ reqBody, err := io.ReadAll(req.Body)
if err != nil {
return util.JSONResponse{
Code: http.StatusBadRequest,
diff --git a/clientapi/routing/register_secret_test.go b/clientapi/routing/register_secret_test.go
index e702b215..a2ed3585 100644
--- a/clientapi/routing/register_secret_test.go
+++ b/clientapi/routing/register_secret_test.go
@@ -2,7 +2,7 @@ package routing
import (
"bytes"
- "io/ioutil"
+ "io"
"testing"
"github.com/patrickmn/go-cache"
@@ -13,7 +13,7 @@ func TestSharedSecretRegister(t *testing.T) {
jsonStr := []byte(`{"admin":false,"mac":"f1ba8d37123866fd659b40de4bad9b0f8965c565","nonce":"759f047f312b99ff428b21d581256f8592b8976e58bc1b543972dc6147e529a79657605b52d7becd160ff5137f3de11975684319187e06901955f79e5a6c5a79","password":"wonderland","username":"alice"}`)
sharedSecret := "dendritetest"
- req, err := NewSharedSecretRegistrationRequest(ioutil.NopCloser(bytes.NewBuffer(jsonStr)))
+ req, err := NewSharedSecretRegistrationRequest(io.NopCloser(bytes.NewBuffer(jsonStr)))
if err != nil {
t.Fatalf("failed to read request: %s", err)
}