delete deprecated ioutil

This commit is contained in:
demoManito 2022-09-19 00:18:18 +08:00
parent 814cd188eb
commit 4c3e9ed1f7
8 changed files with 26 additions and 30 deletions

View File

@ -1912,7 +1912,7 @@ func loadTemplate() (*template.Template, error) {
if file.IsDir() || !strings.HasSuffix(name, ".tmpl") {
continue
}
h, err := ioutil.ReadAll(file)
h, err := io.ReadAll(file)
if err != nil {
return nil, err
}

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")
@ -1351,13 +1350,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

@ -7,7 +7,6 @@ package gin
import (
"errors"
"io"
"io/ioutil"
"log"
"math"
"mime/multipart"
@ -748,7 +747,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
}
@ -867,7 +866,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) {
fmt.Println(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) {
fmt.Println(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) {
fmt.Println(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) {
fmt.Println(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) {
fmt.Println(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) {
fmt.Println(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) {
fmt.Println(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) {
fmt.Println(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) {
fmt.Println(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) {
fmt.Println(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) {
fmt.Println(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)
}