Skip to content

Commit fd57e80

Browse files
testwillginuerzh
authored andcommitted
chore: remove refs to deprecated io/ioutil
1 parent 7e1af1b commit fd57e80

File tree

10 files changed

+21
-27
lines changed

10 files changed

+21
-27
lines changed

cmd/gost/cfg.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"crypto/x509"
77
"encoding/json"
88
"errors"
9-
"io/ioutil"
109
"net"
1110
"net/url"
1211
"os"
@@ -71,7 +70,7 @@ func loadCA(caFile string) (cp *x509.CertPool, err error) {
7170
return
7271
}
7372
cp = x509.NewCertPool()
74-
data, err := ioutil.ReadFile(caFile)
73+
data, err := os.ReadFile(caFile)
7574
if err != nil {
7675
return nil, err
7776
}

cmd/gost/peer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"encoding/json"
77
"io"
8-
"io/ioutil"
98
"strconv"
109
"strings"
1110
"time"
@@ -83,7 +82,7 @@ func (cfg *peerConfig) Reload(r io.Reader) error {
8382
}
8483

8584
func (cfg *peerConfig) parse(r io.Reader) error {
86-
data, err := ioutil.ReadAll(r)
85+
data, err := io.ReadAll(r)
8786
if err != nil {
8887
return err
8988
}

common_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"net"
1211
"net/http"
1312
"net/url"
@@ -36,7 +35,7 @@ func init() {
3635

3736
var (
3837
httpTestHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
39-
data, _ := ioutil.ReadAll(r.Body)
38+
data, _ := io.ReadAll(r.Body)
4039
if len(data) == 0 {
4140
data = []byte("Hello World!")
4241
}
@@ -87,7 +86,7 @@ func httpRoundtrip(conn net.Conn, targetURL string, data []byte) (err error) {
8786
return errors.New(resp.Status)
8887
}
8988

90-
recv, err := ioutil.ReadAll(resp.Body)
89+
recv, err := io.ReadAll(resp.Body)
9190
if err != nil {
9291
return
9392
}

dns.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/base64"
88
"errors"
99
"io"
10-
"io/ioutil"
1110
"net"
1211
"net/http"
1312
"strconv"
@@ -267,7 +266,7 @@ func (l *dnsListener) ServeHTTP(w http.ResponseWriter, r *http.Request) {
267266
return
268267
}
269268

270-
buf, err = ioutil.ReadAll(r.Body)
269+
buf, err = io.ReadAll(r.Body)
271270
if err != nil {
272271
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
273272
return

http2.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"errors"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"net"
1413
"net/http"
1514
"net/http/httputil"
@@ -389,7 +388,7 @@ func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) {
389388
ProtoMajor: 2,
390389
ProtoMinor: 0,
391390
Header: http.Header{},
392-
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
391+
Body: io.NopCloser(bytes.NewReader([]byte{})),
393392
}
394393

395394
if !h.authenticate(w, r, resp) {

http2_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"crypto/rand"
66
"crypto/tls"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net"
1010
"net/http"
1111
"net/http/httptest"
@@ -997,7 +997,7 @@ func TestHTTP2ProxyWithWebProbeResist(t *testing.T) {
997997
if err != nil {
998998
t.Error(err)
999999
}
1000-
recv, _ := ioutil.ReadAll(conn)
1000+
recv, _ := io.ReadAll(conn)
10011001
if !bytes.Equal(recv, []byte("Hello World!")) {
10021002
t.Error("data not equal")
10031003
}
@@ -1053,7 +1053,7 @@ func TestHTTP2ProxyWithHostProbeResist(t *testing.T) {
10531053
Proto: "HTTP/2.0",
10541054
ProtoMajor: 2,
10551055
ProtoMinor: 0,
1056-
Body: ioutil.NopCloser(bytes.NewReader(sendData)),
1056+
Body: io.NopCloser(bytes.NewReader(sendData)),
10571057
Host: "github.com:443",
10581058
ContentLength: int64(len(sendData)),
10591059
}
@@ -1068,7 +1068,7 @@ func TestHTTP2ProxyWithHostProbeResist(t *testing.T) {
10681068
t.Error("got non-200 status:", resp.Status)
10691069
}
10701070

1071-
recv, _ := ioutil.ReadAll(resp.Body)
1071+
recv, _ := io.ReadAll(resp.Body)
10721072
if !bytes.Equal(sendData, recv) {
10731073
t.Error("data not equal")
10741074
}
@@ -1105,7 +1105,7 @@ func TestHTTP2ProxyWithFileProbeResist(t *testing.T) {
11051105
if err != nil {
11061106
t.Error(err)
11071107
}
1108-
recv, _ := ioutil.ReadAll(conn)
1108+
recv, _ := io.ReadAll(conn)
11091109
if !bytes.Equal(recv, []byte("Hello World!")) {
11101110
t.Error("data not equal")
11111111
}

http_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"crypto/rand"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net"
99
"net/http"
1010
"net/http/httptest"
@@ -249,7 +249,7 @@ func TestHTTPProxyWithWebProbeResist(t *testing.T) {
249249
t.Error("got status:", resp.Status)
250250
}
251251

252-
recv, _ := ioutil.ReadAll(resp.Body)
252+
recv, _ := io.ReadAll(resp.Body)
253253
if !bytes.Equal(recv, []byte("Hello World!")) {
254254
t.Error("data not equal")
255255
}
@@ -296,7 +296,7 @@ func TestHTTPProxyWithHostProbeResist(t *testing.T) {
296296
t.Error("got status:", resp.Status)
297297
}
298298

299-
recv, _ := ioutil.ReadAll(resp.Body)
299+
recv, _ := io.ReadAll(resp.Body)
300300
if !bytes.Equal(sendData, recv) {
301301
t.Error("data not equal")
302302
}
@@ -332,7 +332,7 @@ func TestHTTPProxyWithFileProbeResist(t *testing.T) {
332332
t.Error("got status:", resp.Status)
333333
}
334334

335-
recv, _ := ioutil.ReadAll(resp.Body)
335+
recv, _ := io.ReadAll(resp.Body)
336336
if !bytes.Equal(recv, []byte("Hello World!")) {
337337
t.Error("data not equal, got:", string(recv))
338338
}

resolver.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"errors"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"net"
1312
"net/http"
1413
"net/url"
@@ -915,7 +914,7 @@ func (ex *dohExchanger) Exchange(ctx context.Context, query []byte) ([]byte, err
915914
}
916915

917916
// Read wireformat response from the body
918-
buf, err := ioutil.ReadAll(resp.Body)
917+
buf, err := io.ReadAll(resp.Body)
919918
if err != nil {
920919
return nil, fmt.Errorf("failed to read the response body: %s", err)
921920
}

sni_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"crypto/tls"
88
"errors"
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"net/http"
1212
"net/http/httptest"
1313
"net/url"
@@ -69,7 +69,7 @@ func sniRoundtrip(client *Client, server *Server, targetURL string, data []byte)
6969
return errors.New(resp.Status)
7070
}
7171

72-
recv, err := ioutil.ReadAll(resp.Body)
72+
recv, err := io.ReadAll(resp.Body)
7373
if err != nil {
7474
return
7575
}

ssh.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/binary"
77
"errors"
88
"fmt"
9-
"io/ioutil"
9+
"os"
1010
"net"
1111
"strconv"
1212
"strings"
@@ -33,7 +33,7 @@ var (
3333

3434
// ParseSSHKeyFile parses ssh key file.
3535
func ParseSSHKeyFile(fp string) (ssh.Signer, error) {
36-
key, err := ioutil.ReadFile(fp)
36+
key, err := os.ReadFile(fp)
3737
if err != nil {
3838
return nil, err
3939
}
@@ -42,7 +42,7 @@ func ParseSSHKeyFile(fp string) (ssh.Signer, error) {
4242

4343
// ParseSSHAuthorizedKeysFile parses ssh Authorized Keys file.
4444
func ParseSSHAuthorizedKeysFile(fp string) (map[string]bool, error) {
45-
authorizedKeysBytes, err := ioutil.ReadFile(fp)
45+
authorizedKeysBytes, err := os.ReadFile(fp)
4646
if err != nil {
4747
return nil, err
4848
}

0 commit comments

Comments
 (0)