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)
This commit is contained in:
Shelikhoo 2021-09-27 23:02:19 +01:00
parent be4dd56ac7
commit 0c3105691f
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
8 changed files with 11 additions and 11 deletions

View File

@ -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) {

View File

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

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

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

View File

@ -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))