From 81a52389aaecfc33e5eb3b105cd929156bde32a8 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Tue, 5 Apr 2022 12:48:27 +0200 Subject: [PATCH] Stop using deprecated ioutil package. --- backend_client.go | 6 +++--- backend_client_test.go | 6 +++--- backend_server.go | 3 +-- backend_server_test.go | 36 ++++++++++++++++++------------------ client/main.go | 4 ++-- geoip.go | 3 +-- geoip_test.go | 7 ++++--- hub_test.go | 8 ++++---- mcu_proxy.go | 4 ++-- proxy/proxy_server_test.go | 6 +++--- proxy/proxy_tokens_static.go | 4 ++-- room_test.go | 10 +++++----- 12 files changed, 48 insertions(+), 49 deletions(-) diff --git a/backend_client.go b/backend_client.go index 41565a1..de64e1d 100644 --- a/backend_client.go +++ b/backend_client.go @@ -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 diff --git a/backend_client_test.go b/backend_client_test.go index 88927fa..c9ff35e 100644 --- a/backend_client_test.go +++ b/backend_client_test.go @@ -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 diff --git a/backend_server.go b/backend_server.go index 0efa5ae..8eafdb8 100644 --- a/backend_server.go +++ b/backend_server.go @@ -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) diff --git a/backend_server_test.go b/backend_server_test.go index 26341ef..cd6dba2 100644 --- a/backend_server_test.go +++ b/backend_server_test.go @@ -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) } diff --git a/client/main.go b/client/main.go index 48f592a..1338de9 100644 --- a/client/main.go +++ b/client/main.go @@ -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 diff --git a/geoip.go b/geoip.go index 1d70f4e..40cd4e1 100644 --- a/geoip.go +++ b/geoip.go @@ -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 } diff --git a/geoip_test.go b/geoip_test.go index eba29f0..2d359dd 100644 --- a/geoip_test.go +++ b/geoip_test.go @@ -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 diff --git a/hub_test.go b/hub_test.go index 8386817..0326236 100644 --- a/hub_test.go +++ b/hub_test.go @@ -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) } diff --git a/mcu_proxy.go b/mcu_proxy.go index 01e8fdc..1d12272 100644 --- a/mcu_proxy.go +++ b/mcu_proxy.go @@ -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) } diff --git a/proxy/proxy_server_test.go b/proxy/proxy_server_test.go index 229546f..62e6072 100644 --- a/proxy/proxy_server_test.go +++ b/proxy/proxy_server_test.go @@ -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) } diff --git a/proxy/proxy_tokens_static.go b/proxy/proxy_tokens_static.go index a3008de..8ee7fb8 100644 --- a/proxy/proxy_tokens_static.go +++ b/proxy/proxy_tokens_static.go @@ -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) diff --git a/room_test.go b/room_test.go index a4a105c..49f3dcb 100644 --- a/room_test.go +++ b/room_test.go @@ -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) }