refactor: move from io/ioutil to io and os packages

The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

Reference: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2022-09-15 20:06:59 +08:00
committed by Brad Fitzpatrick
parent 027111fb5a
commit f0347e841f
60 changed files with 112 additions and 156 deletions

View File

@@ -2,8 +2,8 @@ package ssh
import (
"io"
"io/ioutil"
"net"
"os"
"path"
"sync"
@@ -36,7 +36,7 @@ func AgentRequested(sess Session) bool {
// NewAgentListener sets up a temporary Unix socket that can be communicated
// to the session environment and used for forwarding connections.
func NewAgentListener() (net.Listener, error) {
dir, err := ioutil.TempDir("", agentTempDir)
dir, err := os.MkdirTemp("", agentTempDir)
if err != nil {
return nil, err
}

View File

@@ -3,7 +3,7 @@ package ssh_test
import (
"errors"
"io"
"io/ioutil"
"os"
"tailscale.com/tempfork/gliderlabs/ssh"
)
@@ -29,7 +29,7 @@ func ExampleNoPty() {
func ExamplePublicKeyAuth() {
ssh.ListenAndServe(":2222", nil,
ssh.PublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) error {
data, err := ioutil.ReadFile("/path/to/allowed/key.pub")
data, err := os.ReadFile("/path/to/allowed/key.pub")
if err != nil {
return err
}

View File

@@ -1,7 +1,7 @@
package ssh
import (
"io/ioutil"
"os"
gossh "github.com/tailscale/golang-x-crypto/ssh"
)
@@ -26,7 +26,7 @@ func PublicKeyAuth(fn PublicKeyHandler) Option {
// from a PEM file at filepath.
func HostKeyFile(filepath string) Option {
return func(srv *Server) error {
pemBytes, err := ioutil.ReadFile(filepath)
pemBytes, err := os.ReadFile(filepath)
if err != nil {
return err
}

View File

@@ -5,7 +5,6 @@ package ssh
import (
"bytes"
"io/ioutil"
"net"
"strconv"
"strings"
@@ -61,7 +60,7 @@ func TestLocalPortForwardingWorks(t *testing.T) {
if err != nil {
t.Fatalf("Error connecting to %v: %v", l.Addr().String(), err)
}
result, err := ioutil.ReadAll(conn)
result, err := io.ReadAll(conn)
if err != nil {
t.Fatal(err)
}