From 0c3105691f607bf8e9c9ade376a78b49a1c440a7 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Mon, 27 Sep 2021 23:02:19 +0100 Subject: [PATCH] refactor: move from io/ioutil to io and os package (#1298) Author: Eng Zer Jun Date: Mon Sep 27 00:56:31 2021 +0800 refactor: move from io/ioutil to io and os package (#1298) --- app/dns/nameserver_doh.go | 4 ++-- common/common.go | 2 +- common/drain/drainer.go | 2 +- infra/conf/mergers/merge.go | 2 +- infra/conf/mergers/merger_base.go | 2 +- testing/scenarios/common.go | 2 +- testing/scenarios/feature_test.go | 2 +- testing/scenarios/http_test.go | 6 +++--- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/dns/nameserver_doh.go b/app/dns/nameserver_doh.go index 5d6e8c8b6e7..d7ecf66c6f5 100644 --- a/app/dns/nameserver_doh.go +++ b/app/dns/nameserver_doh.go @@ -280,11 +280,11 @@ func (s *DoHNameServer) dohHTTPSContext(ctx context.Context, b []byte) ([]byte, defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - io.Copy(ioutil.Discard, resp.Body) // flush resp.Body so that the conn is reusable + io.Copy(io.Discard, resp.Body) // flush resp.Body so that the conn is reusable return nil, fmt.Errorf("DOH server returned code %d", resp.StatusCode) } - return ioutil.ReadAll(resp.Body) + return io.ReadAll(resp.Body) } func (s *DoHNameServer) findIPsForDomain(domain string, option dns_feature.IPOption) ([]net.IP, error) { diff --git a/common/common.go b/common/common.go index c73d8f14527..035fafc0194 100644 --- a/common/common.go +++ b/common/common.go @@ -153,7 +153,7 @@ func FetchHTTPContent(target string) ([]byte, error) { return nil, newError("unexpected HTTP status code: ", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { return nil, newError("failed to read HTTP response").Base(err) } diff --git a/common/drain/drainer.go b/common/drain/drainer.go index 5ed887abc6b..71c3db221ec 100644 --- a/common/drain/drainer.go +++ b/common/drain/drainer.go @@ -36,7 +36,7 @@ func (d *BehaviorSeedLimitedDrainer) Drain(reader io.Reader) error { } func drainReadN(reader io.Reader, n int) error { - _, err := io.CopyN(ioutil.Discard, reader, int64(n)) + _, err := io.CopyN(io.Discard, reader, int64(n)) return err } diff --git a/infra/conf/mergers/merge.go b/infra/conf/mergers/merge.go index 9be9d5eb021..38c3d323e66 100644 --- a/infra/conf/mergers/merge.go +++ b/infra/conf/mergers/merge.go @@ -50,7 +50,7 @@ func Merge(input interface{}, m map[string]interface{}) error { } case io.Reader: // read to []byte incase it tries different mergers - bs, err := ioutil.ReadAll(v) + bs, err := io.ReadAll(v) if err != nil { return err } diff --git a/infra/conf/mergers/merger_base.go b/infra/conf/mergers/merger_base.go index 7e6302f2406..125a922ab2f 100644 --- a/infra/conf/mergers/merger_base.go +++ b/infra/conf/mergers/merger_base.go @@ -85,7 +85,7 @@ func loadFile(file string, target map[string]interface{}, converter func(v []byt } func loadReader(reader io.Reader, target map[string]interface{}, converter func(v []byte) ([]byte, error)) error { - bs, err := ioutil.ReadAll(reader) + bs, err := io.ReadAll(reader) if err != nil { return err } diff --git a/testing/scenarios/common.go b/testing/scenarios/common.go index ebef3ec31cb..138376a5f1d 100644 --- a/testing/scenarios/common.go +++ b/testing/scenarios/common.go @@ -102,7 +102,7 @@ func genTestBinaryPath() { testBinaryPathGen.Do(func() { var tempDir string common.Must(retry.Timed(5, 100).On(func() error { - dir, err := ioutil.TempDir("", "v2ray") + dir, err := os.MkdirTemp("", "v2ray") if err != nil { return err } diff --git a/testing/scenarios/feature_test.go b/testing/scenarios/feature_test.go index c693d7ebb80..93eb8492b8a 100644 --- a/testing/scenarios/feature_test.go +++ b/testing/scenarios/feature_test.go @@ -644,7 +644,7 @@ func TestDomainSniffing(t *testing.T) { if resp.StatusCode != 200 { t.Error("unexpected status code: ", resp.StatusCode) } - common.Must(resp.Write(ioutil.Discard)) + common.Must(resp.Write(io.Discard)) } } diff --git a/testing/scenarios/http_test.go b/testing/scenarios/http_test.go index 99af84210bc..ad940a1853a 100644 --- a/testing/scenarios/http_test.go +++ b/testing/scenarios/http_test.go @@ -75,7 +75,7 @@ func TestHttpConformance(t *testing.T) { t.Fatal("status: ", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) common.Must(err) if string(content) != "Home" { t.Fatal("body: ", string(content)) @@ -271,7 +271,7 @@ func TestHttpPost(t *testing.T) { t.Fatal("status: ", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) common.Must(err) if r := cmp.Diff(content, xor(payload)); r != "" { t.Fatal(r) @@ -368,7 +368,7 @@ func TestHttpBasicAuth(t *testing.T) { t.Fatal("status: ", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) common.Must(err) if string(content) != "Home" { t.Fatal("body: ", string(content))