remove deprecated of package io/ioutil (#3395)

This commit is contained in:
Qt 2022-11-17 22:35:55 +08:00 committed by GitHub
parent 234a1d33f7
commit 6150c488e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 31 deletions

View File

@ -9,7 +9,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
@ -656,12 +655,12 @@ func TestBindingFormFilesMultipart(t *testing.T) {
// file from os
f, _ := os.Open("form.go")
defer f.Close()
fileActual, _ := ioutil.ReadAll(f)
fileActual, _ := io.ReadAll(f)
// file from multipart
mf, _ := obj.File.Open()
defer mf.Close()
fileExpect, _ := ioutil.ReadAll(mf)
fileExpect, _ := io.ReadAll(mf)
assert.Equal(t, FormMultipart.Name(), "multipart/form-data")
assert.Equal(t, obj.Foo, "bar")
@ -1347,13 +1346,13 @@ func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body
obj := protoexample.Test{}
req := requestWithBody("POST", path, body)
req.Body = ioutil.NopCloser(&hook{})
req.Body = io.NopCloser(&hook{})
req.Header.Add("Content-Type", MIMEPROTOBUF)
err := b.Bind(req, &obj)
assert.Error(t, err)
invalidobj := FooStruct{}
req.Body = ioutil.NopCloser(strings.NewReader(`{"msg":"hello"}`))
req.Body = io.NopCloser(strings.NewReader(`{"msg":"hello"}`))
req.Header.Add("Content-Type", MIMEPROTOBUF)
err = b.Bind(req, &invalidobj)
assert.Error(t, err)

View File

@ -6,7 +6,7 @@ package binding
import (
"bytes"
"io/ioutil"
"io"
"mime/multipart"
"net/http"
"testing"
@ -129,7 +129,7 @@ func assertMultipartFileHeader(t *testing.T, fh *multipart.FileHeader, file test
fl, err := fh.Open()
assert.NoError(t, err)
body, err := ioutil.ReadAll(fl)
body, err := io.ReadAll(fl)
assert.NoError(t, err)
assert.Equal(t, string(file.Content), string(body))

View File

@ -6,7 +6,7 @@ package binding
import (
"errors"
"io/ioutil"
"io"
"net/http"
"google.golang.org/protobuf/proto"
@ -19,7 +19,7 @@ func (protobufBinding) Name() string {
}
func (b protobufBinding) Bind(req *http.Request, obj any) error {
buf, err := ioutil.ReadAll(req.Body)
buf, err := io.ReadAll(req.Body)
if err != nil {
return err
}

View File

@ -7,7 +7,6 @@ package gin
import (
"errors"
"io"
"io/ioutil"
"log"
"math"
"mime/multipart"
@ -753,7 +752,7 @@ func (c *Context) ShouldBindBodyWith(obj any, bb binding.BindingBody) (err error
}
}
if body == nil {
body, err = ioutil.ReadAll(c.Request.Body)
body, err = io.ReadAll(c.Request.Body)
if err != nil {
return err
}
@ -872,7 +871,7 @@ func (c *Context) GetHeader(key string) string {
// GetRawData returns stream data.
func (c *Context) GetRawData() ([]byte, error) {
return ioutil.ReadAll(c.Request.Body)
return io.ReadAll(c.Request.Body)
}
// SetSameSite with cookie

View File

@ -9,7 +9,7 @@ import (
"crypto/tls"
"fmt"
"html/template"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
@ -43,7 +43,7 @@ func testRequest(t *testing.T, params ...string) {
assert.NoError(t, err)
defer resp.Body.Close()
body, ioerr := ioutil.ReadAll(resp.Body)
body, ioerr := io.ReadAll(resp.Body)
assert.NoError(t, ioerr)
var responseStatus = "200 OK"

View File

@ -8,7 +8,7 @@ import (
"crypto/tls"
"fmt"
"html/template"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
@ -76,7 +76,7 @@ func TestLoadHTMLGlobDebugMode(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
}
@ -114,7 +114,7 @@ func TestH2c(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
}
@ -134,7 +134,7 @@ func TestLoadHTMLGlobTestMode(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
}
@ -154,7 +154,7 @@ func TestLoadHTMLGlobReleaseMode(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
}
@ -181,7 +181,7 @@ func TestLoadHTMLGlobUsingTLS(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
}
@ -201,7 +201,7 @@ func TestLoadHTMLGlobFromFuncMap(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "Date: 2017/07/01", string(resp))
}
@ -232,7 +232,7 @@ func TestLoadHTMLFilesTestMode(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
}
@ -252,7 +252,7 @@ func TestLoadHTMLFilesDebugMode(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
}
@ -272,7 +272,7 @@ func TestLoadHTMLFilesReleaseMode(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
}
@ -299,7 +299,7 @@ func TestLoadHTMLFilesUsingTLS(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
}
@ -319,7 +319,7 @@ func TestLoadHTMLFilesFuncMap(t *testing.T) {
t.Error(err)
}
resp, _ := ioutil.ReadAll(res.Body)
resp, _ := io.ReadAll(res.Body)
assert.Equal(t, "Date: 2017/07/01", string(resp))
}

View File

@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
@ -121,7 +120,7 @@ func stack(skip int) []byte {
// Print this much at least. If we can't find the source, it won't show.
fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc)
if file != lastFile {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
continue
}

View File

@ -6,7 +6,6 @@ package gin
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@ -294,7 +293,7 @@ func TestRouteParamsByNameWithExtraSlash(t *testing.T) {
func TestRouteStaticFile(t *testing.T) {
// SETUP file
testRoot, _ := os.Getwd()
f, err := ioutil.TempFile(testRoot, "")
f, err := os.CreateTemp(testRoot, "")
if err != nil {
t.Error(err)
}
@ -329,7 +328,7 @@ func TestRouteStaticFile(t *testing.T) {
func TestRouteStaticFileFS(t *testing.T) {
// SETUP file
testRoot, _ := os.Getwd()
f, err := ioutil.TempFile(testRoot, "")
f, err := os.CreateTemp(testRoot, "")
if err != nil {
t.Error(err)
}