Don't use deprecated functions from io/ioutil

This commit is contained in:
Ingo Oppermann
2022-08-18 10:27:33 +03:00
parent 5bd04817cc
commit 6802830c62
16 changed files with 41 additions and 48 deletions

View File

@@ -2,7 +2,7 @@ package resolver
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"time"
@@ -79,7 +79,7 @@ func (r *queryResolver) playoutRequest(method, addr, path, contentType string, d
defer response.Body.Close()
// Read the whole response
data, err = ioutil.ReadAll(response.Body)
data, err = io.ReadAll(response.Body)
if err != nil {
return nil, err
}

View File

@@ -1,7 +1,7 @@
package api
import (
"io/ioutil"
"io"
"net/http"
"net/url"
"sort"
@@ -96,7 +96,7 @@ func (h *MemFSHandler) PatchFile(c echo.Context) error {
req := c.Request()
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
if err != nil {
return api.Err(http.StatusBadRequest, "Failed reading request body", "%s", err)
}

View File

@@ -3,7 +3,7 @@ package api
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
@@ -59,7 +59,7 @@ func (h *PlayoutHandler) Status(c echo.Context) error {
defer response.Body.Close()
// Read the whole response
data, err := ioutil.ReadAll(response.Body)
data, err := io.ReadAll(response.Body)
if err != nil {
return api.Err(http.StatusInternalServerError, "", "%s", err)
}
@@ -122,7 +122,7 @@ func (h *PlayoutHandler) Keyframe(c echo.Context) error {
defer response.Body.Close()
// Read the whole response
data, err := ioutil.ReadAll(response.Body)
data, err := io.ReadAll(response.Body)
if err != nil {
return api.Err(http.StatusInternalServerError, "", "%s", err)
}
@@ -162,7 +162,7 @@ func (h *PlayoutHandler) EncodeErrorframe(c echo.Context) error {
defer response.Body.Close()
// Read the whole response
data, err := ioutil.ReadAll(response.Body)
data, err := io.ReadAll(response.Body)
if err != nil {
return api.Err(http.StatusInternalServerError, "", "%s", err)
}
@@ -195,7 +195,7 @@ func (h *PlayoutHandler) SetErrorframe(c echo.Context) error {
return api.Err(http.StatusNotFound, "Unknown process or input", "%s", err)
}
data, err := ioutil.ReadAll(c.Request().Body)
data, err := io.ReadAll(c.Request().Body)
if err != nil {
return api.Err(http.StatusBadRequest, "Failed to read request body", "%s", err)
}
@@ -210,7 +210,7 @@ func (h *PlayoutHandler) SetErrorframe(c echo.Context) error {
defer response.Body.Close()
// Read the whole response
data, err = ioutil.ReadAll(response.Body)
data, err = io.ReadAll(response.Body)
if err != nil {
return api.Err(http.StatusInternalServerError, "", "%s", err)
}
@@ -249,7 +249,7 @@ func (h *PlayoutHandler) ReopenInput(c echo.Context) error {
defer response.Body.Close()
// Read the whole response
data, err := ioutil.ReadAll(response.Body)
data, err := io.ReadAll(response.Body)
if err != nil {
return api.Err(http.StatusInternalServerError, "", "%s", err)
}
@@ -281,7 +281,7 @@ func (h *PlayoutHandler) SetStream(c echo.Context) error {
return api.Err(http.StatusNotFound, "Unknown process or input", "%s", err)
}
data, err := ioutil.ReadAll(c.Request().Body)
data, err := io.ReadAll(c.Request().Body)
if err != nil {
return api.Err(http.StatusBadRequest, "Failed to read request body", "%s", err)
}
@@ -296,7 +296,7 @@ func (h *PlayoutHandler) SetStream(c echo.Context) error {
defer response.Body.Close()
// Read the whole response
data, err = ioutil.ReadAll(response.Body)
data, err = io.ReadAll(response.Body)
if err != nil {
return api.Err(http.StatusInternalServerError, "", "%s", err)
}

View File

@@ -2,7 +2,7 @@ package util
import (
"fmt"
"io/ioutil"
"io"
"net/url"
"strings"
@@ -24,7 +24,7 @@ func ShouldBindJSONValidation(c echo.Context, obj interface{}, validate bool) er
return fmt.Errorf("request doesn't contain JSON content")
}
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
if err != nil {
return err
}

View File

@@ -6,7 +6,7 @@ import (
"crypto"
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"sync"
"time"
@@ -324,7 +324,7 @@ func (j *jwksImpl) refresh() (err error) {
// Read the raw JWKs from the body of the response.
var jwksBytes []byte
if jwksBytes, err = ioutil.ReadAll(resp.Body); err != nil {
if jwksBytes, err = io.ReadAll(resp.Body); err != nil {
return err
}

View File

@@ -4,7 +4,6 @@ import (
"bufio"
"compress/gzip"
"io"
"io/ioutil"
"net"
"net/http"
"strings"
@@ -108,7 +107,7 @@ func NewWithConfig(config Config) echo.MiddlewareFunc {
// nothing is written to body or error is returned.
// See issue #424, #407.
res.Writer = rw
w.Reset(ioutil.Discard)
w.Reset(io.Discard)
}
w.Close()
pool.Put(w)
@@ -183,7 +182,7 @@ func (w *gzipResponseWriter) Push(target string, opts *http.PushOptions) error {
func gzipPool(config Config) sync.Pool {
return sync.Pool{
New: func() interface{} {
w, err := gzip.NewWriterLevel(ioutil.Discard, config.Level)
w, err := gzip.NewWriterLevel(io.Discard, config.Level)
if err != nil {
return err
}

View File

@@ -5,9 +5,9 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
@@ -57,7 +57,7 @@ func DummyEcho() *echo.Echo {
router.HideBanner = true
router.HidePort = true
router.HTTPErrorHandler = errorhandler.HTTPErrorHandler
router.Logger.SetOutput(ioutil.Discard)
router.Logger.SetOutput(io.Discard)
router.Validator = validator.New()
return router
@@ -89,7 +89,7 @@ func CheckResponse(t *testing.T, res *http.Response) *Response {
Code: res.StatusCode,
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
require.Equal(t, nil, err)
if strings.Contains(res.Header.Get("Content-Type"), "application/json") {
@@ -122,7 +122,7 @@ func Validate(t *testing.T, datatype, data interface{}) bool {
}
func Read(t *testing.T, path string) io.Reader {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
require.Equal(t, nil, err)
return bytes.NewReader(data)