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

This commit is contained in:
kekeimiku
2021-09-29 10:33:57 +08:00
committed by GitHub
parent 72a7fd948e
commit 0cee1877e3
19 changed files with 38 additions and 44 deletions

View File

@@ -17,7 +17,6 @@ package config
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
@@ -77,7 +76,7 @@ func getIncludeContents(paths []string) ([]byte, error) {
if _, err := os.Stat(absDir); os.IsNotExist(err) {
return nil, err
}
files, err := ioutil.ReadDir(absDir)
files, err := os.ReadDir(absDir)
if err != nil {
return nil, err
}

View File

@@ -16,7 +16,6 @@ package config
import (
"bytes"
"io/ioutil"
"os"
"strings"
"text/template"
@@ -67,7 +66,7 @@ func RenderContent(in []byte) (out []byte, err error) {
func GetRenderedConfFromFile(path string) (out []byte, err error) {
var b []byte
b, err = ioutil.ReadFile(path)
b, err = os.ReadFile(path)
if err != nil {
return
}

View File

@@ -16,7 +16,6 @@ package plugin
import (
"io"
"io/ioutil"
"log"
"net"
@@ -43,7 +42,7 @@ func NewSocks5Plugin(params map[string]string) (p Plugin, err error) {
passwd := params["plugin_passwd"]
cfg := &gosocks5.Config{
Logger: log.New(ioutil.Discard, "", log.LstdFlags),
Logger: log.New(io.Discard, "", log.LstdFlags),
}
if user != "" || passwd != "" {
cfg.Credentials = gosocks5.StaticCredentials(map[string]string{user: passwd})

View File

@@ -20,7 +20,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"reflect"
@@ -116,7 +116,7 @@ func (p *httpPlugin) do(ctx context.Context, r *Request, res *Response) error {
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("do http request error code: %d", resp.StatusCode)
}
buf, err = ioutil.ReadAll(resp.Body)
buf, err = io.ReadAll(resp.Body)
if err != nil {
return err
}

View File

@@ -6,8 +6,8 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"math/big"
"os"
)
func newCustomTLSKeyPair(certfile, keyfile string) (*tls.Certificate, error) {
@@ -47,7 +47,7 @@ func newRandomTLSKeyPair() *tls.Certificate {
func newCertPool(caPath string) (*x509.CertPool, error) {
pool := x509.NewCertPool()
caCrt, err := ioutil.ReadFile(caPath)
caCrt, err := os.ReadFile(caPath)
if err != nil {
return nil, err
}

View File

@@ -16,8 +16,9 @@ package vhost
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"os"
frpLog "github.com/fatedier/frp/pkg/util/log"
"github.com/fatedier/frp/pkg/util/version"
@@ -57,7 +58,7 @@ func getNotFoundPageContent() []byte {
err error
)
if NotFoundPagePath != "" {
buf, err = ioutil.ReadFile(NotFoundPagePath)
buf, err = os.ReadFile(NotFoundPagePath)
if err != nil {
frpLog.Warn("read custom 404 page error: %v", err)
buf = []byte(NotFound)
@@ -80,7 +81,7 @@ func notFoundResponse() *http.Response {
ProtoMajor: 1,
ProtoMinor: 0,
Header: header,
Body: ioutil.NopCloser(bytes.NewReader(getNotFoundPageContent())),
Body: io.NopCloser(bytes.NewReader(getNotFoundPageContent())),
}
return res
}