Replace deprecated "io/ioutil"

ioutil.TempFile: Deprecated: As of Go 1.17, this function simply calls os.CreateTemp.

ioutil.ReadFile: Deprecated: As of Go 1.16, this function simply calls os.ReadFile.
pull/1477/head
Mark Chambers 2023-01-15 12:43:07 +00:00 committed by Jack Christensen
parent 7c0c7dc01e
commit 672431c0bd
3 changed files with 6 additions and 9 deletions

View File

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math" "math"
"net" "net"
"net/url" "net/url"
@ -687,7 +686,7 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P
caCertPool := x509.NewCertPool() caCertPool := x509.NewCertPool()
caPath := sslrootcert caPath := sslrootcert
caCert, err := ioutil.ReadFile(caPath) caCert, err := os.ReadFile(caPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read CA file: %w", err) return nil, fmt.Errorf("unable to read CA file: %w", err)
} }
@ -705,7 +704,7 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P
} }
if sslcert != "" && sslkey != "" { if sslcert != "" && sslkey != "" {
buf, err := ioutil.ReadFile(sslkey) buf, err := os.ReadFile(sslkey)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read sslkey: %w", err) return nil, fmt.Errorf("unable to read sslkey: %w", err)
} }
@ -744,7 +743,7 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P
} else { } else {
pemKey = pem.EncodeToMemory(block) pemKey = pem.EncodeToMemory(block)
} }
certfile, err := ioutil.ReadFile(sslcert) certfile, err := os.ReadFile(sslcert)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read cert: %w", err) return nil, fmt.Errorf("unable to read cert: %w", err)
} }

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/user" "os/user"
"runtime" "runtime"
@ -1031,7 +1030,7 @@ func TestParseConfigEnvLibpq(t *testing.T) {
func TestParseConfigReadsPgPassfile(t *testing.T) { func TestParseConfigReadsPgPassfile(t *testing.T) {
t.Parallel() t.Parallel()
tf, err := ioutil.TempFile("", "") tf, err := os.CreateTemp("", "")
require.NoError(t, err) require.NoError(t, err)
defer tf.Close() defer tf.Close()
@ -1060,7 +1059,7 @@ func TestParseConfigReadsPgPassfile(t *testing.T) {
func TestParseConfigReadsPgServiceFile(t *testing.T) { func TestParseConfigReadsPgServiceFile(t *testing.T) {
t.Parallel() t.Parallel()
tf, err := ioutil.TempFile("", "") tf, err := os.CreateTemp("", "")
require.NoError(t, err) require.NoError(t, err)
defer tf.Close() defer tf.Close()

View File

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"math" "math"
"net" "net"
@ -1819,7 +1818,7 @@ func TestConnCopyFromGzipReader(t *testing.T) {
)`).ReadAll() )`).ReadAll()
require.NoError(t, err) require.NoError(t, err)
f, err := ioutil.TempFile("", "*") f, err := os.CreateTemp("", "*")
require.NoError(t, err) require.NoError(t, err)
gw := gzip.NewWriter(f) gw := gzip.NewWriter(f)