Skip to content

Commit

Permalink
refactor: move from io/ioutil to io and os package (#1298)
Browse files Browse the repository at this point in the history
Author: Eng Zer Jun <engzerjun@gmail.com>
Date:   Mon Sep 27 00:56:31 2021 +0800

    refactor: move from io/ioutil to io and os package (#1298)
  • Loading branch information
xiaokangwang committed Sep 27, 2021
1 parent be4dd56 commit 0c31056
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/dns/nameserver_doh.go
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion common/common.go
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion common/drain/drainer.go
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion infra/conf/mergers/merge.go
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion infra/conf/mergers/merger_base.go
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion testing/scenarios/common.go
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion testing/scenarios/feature_test.go
Expand Up @@ -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))
}
}

Expand Down
6 changes: 3 additions & 3 deletions testing/scenarios/http_test.go
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 0c31056

Please sign in to comment.