chore: remove refs to deprecated io/ioutil

This commit is contained in:
guoguangwu 2023-06-19 19:27:03 +08:00 committed by ginuerzh
parent 7e1af1b557
commit fd57e80709
10 changed files with 21 additions and 27 deletions

View File

@ -6,7 +6,6 @@ import (
"crypto/x509" "crypto/x509"
"encoding/json" "encoding/json"
"errors" "errors"
"io/ioutil"
"net" "net"
"net/url" "net/url"
"os" "os"
@ -71,7 +70,7 @@ func loadCA(caFile string) (cp *x509.CertPool, err error) {
return return
} }
cp = x509.NewCertPool() cp = x509.NewCertPool()
data, err := ioutil.ReadFile(caFile) data, err := os.ReadFile(caFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -5,7 +5,6 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -83,7 +82,7 @@ func (cfg *peerConfig) Reload(r io.Reader) error {
} }
func (cfg *peerConfig) parse(r io.Reader) error { func (cfg *peerConfig) parse(r io.Reader) error {
data, err := ioutil.ReadAll(r) data, err := io.ReadAll(r)
if err != nil { if err != nil {
return err return err
} }

View File

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
@ -36,7 +35,7 @@ func init() {
var ( var (
httpTestHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { httpTestHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
data, _ := ioutil.ReadAll(r.Body) data, _ := io.ReadAll(r.Body)
if len(data) == 0 { if len(data) == 0 {
data = []byte("Hello World!") data = []byte("Hello World!")
} }
@ -87,7 +86,7 @@ func httpRoundtrip(conn net.Conn, targetURL string, data []byte) (err error) {
return errors.New(resp.Status) return errors.New(resp.Status)
} }
recv, err := ioutil.ReadAll(resp.Body) recv, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return return
} }

3
dns.go
View File

@ -7,7 +7,6 @@ import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"strconv" "strconv"
@ -267,7 +266,7 @@ func (l *dnsListener) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
buf, err = ioutil.ReadAll(r.Body) buf, err = io.ReadAll(r.Body)
if err != nil { if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return return

View File

@ -9,7 +9,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
@ -389,7 +388,7 @@ func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) {
ProtoMajor: 2, ProtoMajor: 2,
ProtoMinor: 0, ProtoMinor: 0,
Header: http.Header{}, Header: http.Header{},
Body: ioutil.NopCloser(bytes.NewReader([]byte{})), Body: io.NopCloser(bytes.NewReader([]byte{})),
} }
if !h.authenticate(w, r, resp) { if !h.authenticate(w, r, resp) {

View File

@ -5,7 +5,7 @@ import (
"crypto/rand" "crypto/rand"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"io/ioutil" "io"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -997,7 +997,7 @@ func TestHTTP2ProxyWithWebProbeResist(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
recv, _ := ioutil.ReadAll(conn) recv, _ := io.ReadAll(conn)
if !bytes.Equal(recv, []byte("Hello World!")) { if !bytes.Equal(recv, []byte("Hello World!")) {
t.Error("data not equal") t.Error("data not equal")
} }
@ -1053,7 +1053,7 @@ func TestHTTP2ProxyWithHostProbeResist(t *testing.T) {
Proto: "HTTP/2.0", Proto: "HTTP/2.0",
ProtoMajor: 2, ProtoMajor: 2,
ProtoMinor: 0, ProtoMinor: 0,
Body: ioutil.NopCloser(bytes.NewReader(sendData)), Body: io.NopCloser(bytes.NewReader(sendData)),
Host: "github.com:443", Host: "github.com:443",
ContentLength: int64(len(sendData)), ContentLength: int64(len(sendData)),
} }
@ -1068,7 +1068,7 @@ func TestHTTP2ProxyWithHostProbeResist(t *testing.T) {
t.Error("got non-200 status:", resp.Status) t.Error("got non-200 status:", resp.Status)
} }
recv, _ := ioutil.ReadAll(resp.Body) recv, _ := io.ReadAll(resp.Body)
if !bytes.Equal(sendData, recv) { if !bytes.Equal(sendData, recv) {
t.Error("data not equal") t.Error("data not equal")
} }
@ -1105,7 +1105,7 @@ func TestHTTP2ProxyWithFileProbeResist(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
recv, _ := ioutil.ReadAll(conn) recv, _ := io.ReadAll(conn)
if !bytes.Equal(recv, []byte("Hello World!")) { if !bytes.Equal(recv, []byte("Hello World!")) {
t.Error("data not equal") t.Error("data not equal")
} }

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"io/ioutil" "io"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -249,7 +249,7 @@ func TestHTTPProxyWithWebProbeResist(t *testing.T) {
t.Error("got status:", resp.Status) t.Error("got status:", resp.Status)
} }
recv, _ := ioutil.ReadAll(resp.Body) recv, _ := io.ReadAll(resp.Body)
if !bytes.Equal(recv, []byte("Hello World!")) { if !bytes.Equal(recv, []byte("Hello World!")) {
t.Error("data not equal") t.Error("data not equal")
} }
@ -296,7 +296,7 @@ func TestHTTPProxyWithHostProbeResist(t *testing.T) {
t.Error("got status:", resp.Status) t.Error("got status:", resp.Status)
} }
recv, _ := ioutil.ReadAll(resp.Body) recv, _ := io.ReadAll(resp.Body)
if !bytes.Equal(sendData, recv) { if !bytes.Equal(sendData, recv) {
t.Error("data not equal") t.Error("data not equal")
} }
@ -332,7 +332,7 @@ func TestHTTPProxyWithFileProbeResist(t *testing.T) {
t.Error("got status:", resp.Status) t.Error("got status:", resp.Status)
} }
recv, _ := ioutil.ReadAll(resp.Body) recv, _ := io.ReadAll(resp.Body)
if !bytes.Equal(recv, []byte("Hello World!")) { if !bytes.Equal(recv, []byte("Hello World!")) {
t.Error("data not equal, got:", string(recv)) t.Error("data not equal, got:", string(recv))
} }

View File

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
@ -915,7 +914,7 @@ func (ex *dohExchanger) Exchange(ctx context.Context, query []byte) ([]byte, err
} }
// Read wireformat response from the body // Read wireformat response from the body
buf, err := ioutil.ReadAll(resp.Body) buf, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read the response body: %s", err) return nil, fmt.Errorf("failed to read the response body: %s", err)
} }

View File

@ -7,7 +7,7 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
@ -69,7 +69,7 @@ func sniRoundtrip(client *Client, server *Server, targetURL string, data []byte)
return errors.New(resp.Status) return errors.New(resp.Status)
} }
recv, err := ioutil.ReadAll(resp.Body) recv, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return return
} }

6
ssh.go
View File

@ -6,7 +6,7 @@ import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "os"
"net" "net"
"strconv" "strconv"
"strings" "strings"
@ -33,7 +33,7 @@ var (
// ParseSSHKeyFile parses ssh key file. // ParseSSHKeyFile parses ssh key file.
func ParseSSHKeyFile(fp string) (ssh.Signer, error) { func ParseSSHKeyFile(fp string) (ssh.Signer, error) {
key, err := ioutil.ReadFile(fp) key, err := os.ReadFile(fp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -42,7 +42,7 @@ func ParseSSHKeyFile(fp string) (ssh.Signer, error) {
// ParseSSHAuthorizedKeysFile parses ssh Authorized Keys file. // ParseSSHAuthorizedKeysFile parses ssh Authorized Keys file.
func ParseSSHAuthorizedKeysFile(fp string) (map[string]bool, error) { func ParseSSHAuthorizedKeysFile(fp string) (map[string]bool, error) {
authorizedKeysBytes, err := ioutil.ReadFile(fp) authorizedKeysBytes, err := os.ReadFile(fp)
if err != nil { if err != nil {
return nil, err return nil, err
} }