diff --git a/client/admin_api.go b/client/admin_api.go index a3540ff..5d40e2a 100644 --- a/client/admin_api.go +++ b/client/admin_api.go @@ -17,8 +17,9 @@ package client import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" + "os" "sort" "strings" @@ -256,7 +257,7 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) { }() // get new config content - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { res.Code = 400 res.Msg = fmt.Sprintf("read request body error: %v", err) @@ -273,7 +274,7 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) { // get token from origin content token := "" - b, err := ioutil.ReadFile(svr.cfgFile) + b, err := os.ReadFile(svr.cfgFile) if err != nil { res.Code = 400 res.Msg = err.Error() @@ -312,7 +313,7 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) { } content = strings.Join(newRows, "\n") - err = ioutil.WriteFile(svr.cfgFile, []byte(content), 0644) + err = os.WriteFile(svr.cfgFile, []byte(content), 0644) if err != nil { res.Code = 500 res.Msg = fmt.Sprintf("write content to frpc config file error: %v", err) diff --git a/client/health/health.go b/client/health/health.go index 5a7b369..829bee3 100644 --- a/client/health/health.go +++ b/client/health/health.go @@ -19,7 +19,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "net/http" "time" @@ -162,7 +161,7 @@ func (monitor *Monitor) doHTTPCheck(ctx context.Context) error { return err } defer resp.Body.Close() - io.Copy(ioutil.Discard, resp.Body) + io.Copy(io.Discard, resp.Body) if resp.StatusCode/100 != 2 { return fmt.Errorf("do http health check, StatusCode is [%d] not 2xx", resp.StatusCode) diff --git a/client/proxy/proxy.go b/client/proxy/proxy.go index 1b29a75..47ab03c 100644 --- a/client/proxy/proxy.go +++ b/client/proxy/proxy.go @@ -19,7 +19,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net" "strconv" "strings" @@ -401,7 +400,7 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) { fmuxCfg := fmux.DefaultConfig() fmuxCfg.KeepAliveInterval = 5 * time.Second - fmuxCfg.LogOutput = ioutil.Discard + fmuxCfg.LogOutput = io.Discard sess, err := fmux.Server(kcpConn, fmuxCfg) if err != nil { xl.Error("create yamux server from kcp connection error: %v", err) diff --git a/client/service.go b/client/service.go index a74ad3a..b31e07b 100644 --- a/client/service.go +++ b/client/service.go @@ -19,7 +19,7 @@ import ( "crypto/tls" "errors" "fmt" - "io/ioutil" + "io" "net" "runtime" "strconv" @@ -246,7 +246,7 @@ func (svr *Service) login() (conn net.Conn, session *fmux.Session, err error) { if svr.cfg.TCPMux { fmuxCfg := fmux.DefaultConfig() fmuxCfg.KeepAliveInterval = 20 * time.Second - fmuxCfg.LogOutput = ioutil.Discard + fmuxCfg.LogOutput = io.Discard session, err = fmux.Client(conn, fmuxCfg) if err != nil { return diff --git a/client/visitor.go b/client/visitor.go index 36f9bad..7526481 100644 --- a/client/visitor.go +++ b/client/visitor.go @@ -19,7 +19,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net" "sync" "time" @@ -308,7 +307,7 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) { fmuxCfg := fmux.DefaultConfig() fmuxCfg.KeepAliveInterval = 5 * time.Second - fmuxCfg.LogOutput = ioutil.Discard + fmuxCfg.LogOutput = io.Discard sess, err := fmux.Client(remote, fmuxCfg) if err != nil { xl.Error("create yamux session error: %v", err) diff --git a/cmd/frpc/sub/reload.go b/cmd/frpc/sub/reload.go index 35f160d..c625dae 100644 --- a/cmd/frpc/sub/reload.go +++ b/cmd/frpc/sub/reload.go @@ -17,7 +17,7 @@ package sub import ( "encoding/base64" "fmt" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -76,7 +76,7 @@ func reload(clientCfg config.ClientCommonConf) error { return nil } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return err } diff --git a/cmd/frpc/sub/status.go b/cmd/frpc/sub/status.go index 15286d2..52c1c19 100644 --- a/cmd/frpc/sub/status.go +++ b/cmd/frpc/sub/status.go @@ -18,7 +18,7 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -77,7 +77,7 @@ func status(clientCfg config.ClientCommonConf) error { return fmt.Errorf("admin api status code [%d]", resp.StatusCode) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return err } diff --git a/pkg/config/parse.go b/pkg/config/parse.go index cf994c9..7767981 100644 --- a/pkg/config/parse.go +++ b/pkg/config/parse.go @@ -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 } diff --git a/pkg/config/value.go b/pkg/config/value.go index a3114e6..41c6c65 100644 --- a/pkg/config/value.go +++ b/pkg/config/value.go @@ -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 } diff --git a/pkg/plugin/client/socks5.go b/pkg/plugin/client/socks5.go index 79919e4..3a543d9 100644 --- a/pkg/plugin/client/socks5.go +++ b/pkg/plugin/client/socks5.go @@ -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}) diff --git a/pkg/plugin/server/http.go b/pkg/plugin/server/http.go index f4d9c5c..5ca8c06 100644 --- a/pkg/plugin/server/http.go +++ b/pkg/plugin/server/http.go @@ -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 } diff --git a/pkg/transport/tls.go b/pkg/transport/tls.go index a93e092..4a6cd8f 100644 --- a/pkg/transport/tls.go +++ b/pkg/transport/tls.go @@ -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 } diff --git a/pkg/util/vhost/resource.go b/pkg/util/vhost/resource.go index f89348e..446f40f 100644 --- a/pkg/util/vhost/resource.go +++ b/pkg/util/vhost/resource.go @@ -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 } diff --git a/server/service.go b/server/service.go index b854654..97a65f8 100644 --- a/server/service.go +++ b/server/service.go @@ -19,7 +19,7 @@ import ( "context" "crypto/tls" "fmt" - "io/ioutil" + "io" "net" "net/http" "sort" @@ -406,7 +406,7 @@ func (svr *Service) HandleListener(l net.Listener) { if svr.cfg.TCPMux { fmuxCfg := fmux.DefaultConfig() fmuxCfg.KeepAliveInterval = 20 * time.Second - fmuxCfg.LogOutput = ioutil.Discard + fmuxCfg.LogOutput = io.Discard session, err := fmux.Server(frpConn, fmuxCfg) if err != nil { log.Warn("Failed to create mux connection: %v", err) diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index f4b4b6b..344f64c 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -3,7 +3,6 @@ package framework import ( "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -90,7 +89,7 @@ func (f *Framework) BeforeEach() { f.cleanupHandle = AddCleanupAction(f.AfterEach) - dir, err := ioutil.TempDir(os.TempDir(), "frp-e2e-test-*") + dir, err := os.MkdirTemp(os.TempDir(), "frp-e2e-test-*") ExpectNoError(err) f.TempDirectory = dir @@ -260,7 +259,7 @@ func (f *Framework) SetEnvs(envs []string) { func (f *Framework) WriteTempFile(name string, content string) string { filePath := filepath.Join(f.TempDirectory, name) - err := ioutil.WriteFile(filePath, []byte(content), 0766) + err := os.WriteFile(filePath, []byte(content), 0766) ExpectNoError(err) return filePath } diff --git a/test/e2e/framework/process.go b/test/e2e/framework/process.go index 6a98864..a1b1571 100644 --- a/test/e2e/framework/process.go +++ b/test/e2e/framework/process.go @@ -2,7 +2,7 @@ package framework import ( "fmt" - "io/ioutil" + "os" "path/filepath" "time" @@ -30,7 +30,7 @@ func (f *Framework) RunProcesses(serverTemplates []string, clientTemplates []str for i := range serverTemplates { path := filepath.Join(f.TempDirectory, fmt.Sprintf("frp-e2e-server-%d", i)) - err = ioutil.WriteFile(path, []byte(outs[i]), 0666) + err = os.WriteFile(path, []byte(outs[i]), 0666) ExpectNoError(err) flog.Trace("[%s] %s", path, outs[i]) @@ -45,7 +45,7 @@ func (f *Framework) RunProcesses(serverTemplates []string, clientTemplates []str for i := range clientTemplates { index := i + len(serverTemplates) path := filepath.Join(f.TempDirectory, fmt.Sprintf("frp-e2e-client-%d", i)) - err = ioutil.WriteFile(path, []byte(outs[index]), 0666) + err = os.WriteFile(path, []byte(outs[index]), 0666) ExpectNoError(err) flog.Trace("[%s] %s", path, outs[index]) @@ -85,7 +85,7 @@ func (f *Framework) RunFrpc(args ...string) (*process.Process, string, error) { func (f *Framework) GenerateConfigFile(content string) string { f.configFileIndex++ path := filepath.Join(f.TempDirectory, fmt.Sprintf("frp-e2e-config-%d", f.configFileIndex)) - err := ioutil.WriteFile(path, []byte(content), 0666) + err := os.WriteFile(path, []byte(content), 0666) ExpectNoError(err) return path } diff --git a/test/e2e/pkg/request/request.go b/test/e2e/pkg/request/request.go index d9bd54e..5792d53 100644 --- a/test/e2e/pkg/request/request.go +++ b/test/e2e/pkg/request/request.go @@ -6,7 +6,6 @@ import ( "crypto/tls" "fmt" "io" - "io/ioutil" "net" "net/http" "net/url" @@ -219,7 +218,7 @@ func (r *Request) sendHTTPRequest(method, urlstr string, host string, headers ma } ret := &Response{Code: resp.StatusCode, Header: resp.Header} - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/test/e2e/pkg/sdk/client/client.go b/test/e2e/pkg/sdk/client/client.go index b708d60..2bca92e 100644 --- a/test/e2e/pkg/sdk/client/client.go +++ b/test/e2e/pkg/sdk/client/client.go @@ -3,7 +3,7 @@ package client import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net" "net/http" "strconv" @@ -125,7 +125,7 @@ func (c *Client) do(req *http.Request) (string, error) { if resp.StatusCode != 200 { return "", fmt.Errorf("api status code [%d]", resp.StatusCode) } - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { return "", err } diff --git a/test/e2e/plugin/utils.go b/test/e2e/plugin/utils.go index 5eadd80..c0d7db3 100644 --- a/test/e2e/plugin/utils.go +++ b/test/e2e/plugin/utils.go @@ -3,7 +3,7 @@ package plugin import ( "crypto/tls" "encoding/json" - "io/ioutil" + "io" "net/http" plugin "github.com/fatedier/frp/pkg/plugin/server" @@ -21,7 +21,7 @@ func NewHTTPPluginServer(port int, newFunc NewPluginRequest, handler PluginHandl httpserver.WithTlsConfig(tlsConfig), httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { r := newFunc() - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { w.WriteHeader(500) return