Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecated of package io/ioutil #3395

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions binding/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions binding/multipart_form_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package binding

import (
"bytes"
"io/ioutil"
"io"
"mime/multipart"
"net/http"
"testing"
Expand Down Expand Up @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions binding/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package binding

import (
"errors"
"io/ioutil"
"io"
"net/http"

"google.golang.org/protobuf/proto"
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package gin
import (
"errors"
"io"
"io/ioutil"
"log"
"math"
"mime/multipart"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gin_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"crypto/tls"
"fmt"
"html/template"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -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"
Expand Down
24 changes: 12 additions & 12 deletions gin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"crypto/tls"
"fmt"
"html/template"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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))
}

Expand All @@ -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))
}

Expand All @@ -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))
}

Expand All @@ -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))
}

Expand All @@ -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))
}

Expand Down Expand Up @@ -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))
}

Expand All @@ -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))
}

Expand All @@ -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))
}

Expand All @@ -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))
}

Expand All @@ -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))
}

Expand Down
3 changes: 1 addition & 2 deletions recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package gin

import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down