Stop using deprecated ioutil package.

This commit is contained in:
Joachim Bauch 2022-04-05 12:48:27 +02:00
parent 9c2df744c1
commit 81a52389aa
No known key found for this signature in database
GPG Key ID: 77C1D22D53E15F02
12 changed files with 48 additions and 49 deletions

View File

@ -28,7 +28,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
@ -232,7 +232,7 @@ func (b *BackendClient) getCapabilities(ctx context.Context, u *url.URL) (map[st
return nil, ErrUnsupportedContentType
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Printf("Could not read response body from %s: %s", capUrl.String(), err)
return nil, err
@ -363,7 +363,7 @@ func (b *BackendClient) PerformJSONRequest(ctx context.Context, u *url.URL, requ
return ErrUnsupportedContentType
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Printf("Could not read response body from %s: %s", req.URL, err)
return err

View File

@ -25,7 +25,7 @@ import (
"context"
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
@ -66,7 +66,7 @@ func TestPostOnRedirect(t *testing.T) {
http.Redirect(w, r, "/ocs/v2.php/two", http.StatusTemporaryRedirect)
})
r.HandleFunc("/ocs/v2.php/two", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
return
@ -161,7 +161,7 @@ func TestPostOnRedirectStatusFound(t *testing.T) {
http.Redirect(w, r, "/ocs/v2.php/two", http.StatusFound)
})
r.HandleFunc("/ocs/v2.php/two", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
return

View File

@ -29,7 +29,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
@ -268,7 +267,7 @@ func (b *BackendServer) parseRequestBody(f func(http.ResponseWriter, *http.Reque
return
}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
log.Println("Error reading body: ", err)
http.Error(w, "Could not read body", http.StatusBadRequest)

View File

@ -29,7 +29,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
@ -178,7 +178,7 @@ func TestBackendServer_NoAuth(t *testing.T) {
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -207,7 +207,7 @@ func TestBackendServer_InvalidAuth(t *testing.T) {
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -257,7 +257,7 @@ func TestBackendServer_OldCompatAuth(t *testing.T) {
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -277,7 +277,7 @@ func TestBackendServer_InvalidBody(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -304,7 +304,7 @@ func TestBackendServer_UnsupportedRequest(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -361,7 +361,7 @@ func TestBackendServer_RoomInvite(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -456,7 +456,7 @@ func TestBackendServer_RoomDisinvite(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -557,7 +557,7 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -601,7 +601,7 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err = ioutil.ReadAll(res.Body)
body, err = io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -672,7 +672,7 @@ func TestBackendServer_RoomUpdate(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -754,7 +754,7 @@ func TestBackendServer_RoomDelete(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -883,7 +883,7 @@ func TestBackendServer_ParticipantsUpdatePermissions(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -971,7 +971,7 @@ func TestBackendServer_ParticipantsUpdateEmptyPermissions(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -1075,7 +1075,7 @@ func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) {
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -1128,7 +1128,7 @@ func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) {
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -1248,7 +1248,7 @@ func TestBackendServer_RoomMessage(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -1283,7 +1283,7 @@ func TestBackendServer_TurnCredentials(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}

View File

@ -27,7 +27,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
pseudorand "math/rand"
"net"
@ -418,7 +418,7 @@ func (c *SignalingClient) SendMessages(clients []*SignalingClient) {
func registerAuthHandler(router *mux.Router) {
router.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
log.Println("Error reading body:", err)
return

View File

@ -26,7 +26,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
@ -178,7 +177,7 @@ func (g *GeoLookup) updateUrl() error {
continue
}
geoipdata, err = ioutil.ReadAll(tarfile)
geoipdata, err = io.ReadAll(tarfile)
if err != nil {
return err
}

View File

@ -25,7 +25,6 @@ import (
"archive/tar"
"compress/gzip"
"io"
"io/ioutil"
"net"
"net/http"
"os"
@ -157,11 +156,13 @@ func TestGeoLookupFromFile(t *testing.T) {
}
}
tmpfile, err := ioutil.TempFile("", "geoipdb")
tmpfile, err := os.CreateTemp("", "geoipdb")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile.Name())
t.Cleanup(func() {
os.Remove(tmpfile.Name())
})
tarfile := tar.NewReader(body)
foundDatabase := false

View File

@ -24,7 +24,7 @@ package signaling
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
@ -183,7 +183,7 @@ func WaitForHub(ctx context.Context, t *testing.T, h *Hub) {
func validateBackendChecksum(t *testing.T, f func(http.ResponseWriter, *http.Request, *BackendClientRequest) *BackendClientResponse) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal("Error reading body: ", err)
}
@ -2644,7 +2644,7 @@ func TestClientSendOfferPermissionsAudioVideo(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -2773,7 +2773,7 @@ func TestClientSendOfferPermissionsAudioVideoMedia(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}

View File

@ -27,11 +27,11 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
"net/url"
"os"
"sort"
"strconv"
"strings"
@ -1074,7 +1074,7 @@ func NewMcuProxy(config *goconf.ConfigFile) (Mcu, error) {
if tokenKeyFilename == "" {
return nil, fmt.Errorf("No token key configured")
}
tokenKeyData, err := ioutil.ReadFile(tokenKeyFilename)
tokenKeyData, err := os.ReadFile(tokenKeyFilename)
if err != nil {
return nil, fmt.Errorf("Could not read private key from %s: %s", tokenKeyFilename, err)
}

View File

@ -26,7 +26,7 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"os"
"testing"
"time"
@ -59,7 +59,7 @@ func newProxyServerForTest(t *testing.T) (*ProxyServer, *rsa.PrivateKey, func())
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(key),
}
privkey, err := ioutil.TempFile(tempdir, "privkey*.pem")
privkey, err := os.CreateTemp(tempdir, "privkey*.pem")
if err != nil {
t.Fatalf("could not create temporary file for private key: %s", err)
}
@ -75,7 +75,7 @@ func newProxyServerForTest(t *testing.T) (*ProxyServer, *rsa.PrivateKey, func())
Type: "RSA PUBLIC KEY",
Bytes: pubData,
}
pubkey, err := ioutil.TempFile(tempdir, "pubkey*.pem")
pubkey, err := os.CreateTemp(tempdir, "pubkey*.pem")
if err != nil {
t.Fatalf("could not create temporary file for public key: %s", err)
}

View File

@ -23,8 +23,8 @@ package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"sort"
"sync/atomic"
@ -73,7 +73,7 @@ func (t *tokensStatic) load(config *goconf.ConfigFile, ignoreErrors bool) error
continue
}
keyData, err := ioutil.ReadFile(filename)
keyData, err := os.ReadFile(filename)
if err != nil {
if !ignoreErrors {
return fmt.Errorf("Could not read public key from %s: %s", filename, err)

View File

@ -26,7 +26,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"strconv"
"testing"
"time"
@ -137,7 +137,7 @@ func TestRoom_Update(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -273,7 +273,7 @@ func TestRoom_Delete(t *testing.T) {
t.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
@ -510,7 +510,7 @@ func TestRoom_InCallAll(t *testing.T) {
t.Fatal(err)
}
defer res1.Body.Close()
body1, err := ioutil.ReadAll(res1.Body)
body1, err := io.ReadAll(res1.Body)
if err != nil {
t.Error(err)
}
@ -548,7 +548,7 @@ func TestRoom_InCallAll(t *testing.T) {
t.Fatal(err)
}
defer res2.Body.Close()
body2, err := ioutil.ReadAll(res2.Body)
body2, err := io.ReadAll(res2.Body)
if err != nil {
t.Error(err)
}