Browse Source

refactor: move from io/ioutil to io and os package (#1298)

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)
Shelikhoo 4 years ago
parent
commit
0c3105691f

+ 2 - 2
app/dns/nameserver_doh.go

@@ -280,11 +280,11 @@ func (s *DoHNameServer) dohHTTPSContext(ctx context.Context, b []byte) ([]byte,
 
 
 	defer resp.Body.Close()
 	defer resp.Body.Close()
 	if resp.StatusCode != http.StatusOK {
 	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 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) {
 func (s *DoHNameServer) findIPsForDomain(domain string, option dns_feature.IPOption) ([]net.IP, error) {

+ 1 - 1
common/common.go

@@ -153,7 +153,7 @@ func FetchHTTPContent(target string) ([]byte, error) {
 		return nil, newError("unexpected HTTP status code: ", resp.StatusCode)
 		return nil, newError("unexpected HTTP status code: ", resp.StatusCode)
 	}
 	}
 
 
-	content, err := ioutil.ReadAll(resp.Body)
+	content, err := io.ReadAll(resp.Body)
 	if err != nil {
 	if err != nil {
 		return nil, newError("failed to read HTTP response").Base(err)
 		return nil, newError("failed to read HTTP response").Base(err)
 	}
 	}

+ 1 - 1
common/drain/drainer.go

@@ -36,7 +36,7 @@ func (d *BehaviorSeedLimitedDrainer) Drain(reader io.Reader) error {
 }
 }
 
 
 func drainReadN(reader io.Reader, n int) 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
 	return err
 }
 }
 
 

+ 1 - 1
infra/conf/mergers/merge.go

@@ -50,7 +50,7 @@ func Merge(input interface{}, m map[string]interface{}) error {
 		}
 		}
 	case io.Reader:
 	case io.Reader:
 		// read to []byte incase it tries different mergers
 		// read to []byte incase it tries different mergers
-		bs, err := ioutil.ReadAll(v)
+		bs, err := io.ReadAll(v)
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}

+ 1 - 1
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 {
 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 {
 	if err != nil {
 		return err
 		return err
 	}
 	}

+ 1 - 1
testing/scenarios/common.go

@@ -102,7 +102,7 @@ func genTestBinaryPath() {
 	testBinaryPathGen.Do(func() {
 	testBinaryPathGen.Do(func() {
 		var tempDir string
 		var tempDir string
 		common.Must(retry.Timed(5, 100).On(func() error {
 		common.Must(retry.Timed(5, 100).On(func() error {
-			dir, err := ioutil.TempDir("", "v2ray")
+			dir, err := os.MkdirTemp("", "v2ray")
 			if err != nil {
 			if err != nil {
 				return err
 				return err
 			}
 			}

+ 1 - 1
testing/scenarios/feature_test.go

@@ -644,7 +644,7 @@ func TestDomainSniffing(t *testing.T) {
 		if resp.StatusCode != 200 {
 		if resp.StatusCode != 200 {
 			t.Error("unexpected status code: ", resp.StatusCode)
 			t.Error("unexpected status code: ", resp.StatusCode)
 		}
 		}
-		common.Must(resp.Write(ioutil.Discard))
+		common.Must(resp.Write(io.Discard))
 	}
 	}
 }
 }
 
 

+ 3 - 3
testing/scenarios/http_test.go

@@ -75,7 +75,7 @@ func TestHttpConformance(t *testing.T) {
 			t.Fatal("status: ", resp.StatusCode)
 			t.Fatal("status: ", resp.StatusCode)
 		}
 		}
 
 
-		content, err := ioutil.ReadAll(resp.Body)
+		content, err := io.ReadAll(resp.Body)
 		common.Must(err)
 		common.Must(err)
 		if string(content) != "Home" {
 		if string(content) != "Home" {
 			t.Fatal("body: ", string(content))
 			t.Fatal("body: ", string(content))
@@ -271,7 +271,7 @@ func TestHttpPost(t *testing.T) {
 			t.Fatal("status: ", resp.StatusCode)
 			t.Fatal("status: ", resp.StatusCode)
 		}
 		}
 
 
-		content, err := ioutil.ReadAll(resp.Body)
+		content, err := io.ReadAll(resp.Body)
 		common.Must(err)
 		common.Must(err)
 		if r := cmp.Diff(content, xor(payload)); r != "" {
 		if r := cmp.Diff(content, xor(payload)); r != "" {
 			t.Fatal(r)
 			t.Fatal(r)
@@ -368,7 +368,7 @@ func TestHttpBasicAuth(t *testing.T) {
 				t.Fatal("status: ", resp.StatusCode)
 				t.Fatal("status: ", resp.StatusCode)
 			}
 			}
 
 
-			content, err := ioutil.ReadAll(resp.Body)
+			content, err := io.ReadAll(resp.Body)
 			common.Must(err)
 			common.Must(err)
 			if string(content) != "Home" {
 			if string(content) != "Home" {
 				t.Fatal("body: ", string(content))
 				t.Fatal("body: ", string(content))