refactor: change deprecated "io/ioutil" package to recommended "io" package

This commit is contained in:
am3o 2024-02-17 12:47:22 +01:00
parent 35984c0876
commit acce1f1fd9
No known key found for this signature in database
GPG key ID: F76214F50EEA64B5
14 changed files with 25 additions and 39 deletions

View file

@ -2,7 +2,6 @@ package amp
import (
"io"
"io/ioutil"
"math/rand"
"strings"
"testing"
@ -13,7 +12,7 @@ func armorDecodeToString(src string) (string, error) {
if err != nil {
return "", err
}
p, err := ioutil.ReadAll(dec)
p, err := io.ReadAll(dec)
return string(p), err
}

View file

@ -43,7 +43,6 @@ package encapsulation
import (
"errors"
"io"
"io/ioutil"
)
// ErrTooLong is the error returned when an encoded length prefix is longer than
@ -93,7 +92,7 @@ func ReadData(r io.Reader, p []byte) (int, error) {
// If the caller's buffer was too short, discard
// the rest of the data and return
// io.ErrShortBuffer.
_, err = io.CopyN(ioutil.Discard, r, int64(n-numData))
_, err = io.CopyN(io.Discard, r, int64(n-numData))
if err == nil {
err = io.ErrShortBuffer
}
@ -103,7 +102,7 @@ func ReadData(r io.Reader, p []byte) (int, error) {
}
return numData, err
} else if n > 0 {
_, err := io.CopyN(ioutil.Discard, r, int64(n))
_, err := io.CopyN(io.Discard, r, int64(n))
if err == io.EOF {
err = io.ErrUnexpectedEOF
}

View file

@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
@ -87,7 +86,7 @@ func TestWrite(t *testing.T) {
// goroutine, reading from the Conn s and writing to the dataCh
// and errCh channels, whose ultimate effect in the select loop
// below is like
// data, err := ioutil.ReadAll(s)
// data, err := io.ReadAll(s)
dataCh := make(chan []byte)
errCh := make(chan error)
go func() {
@ -162,7 +161,7 @@ func TestConcurrentRead(t *testing.T) {
for i := 0; i < 2; i++ {
go func() {
defer wg.Done()
_, err := io.Copy(ioutil.Discard, s)
_, err := io.Copy(io.Discard, s)
if err != nil {
errCh <- err
}
@ -224,7 +223,7 @@ func TestConcurrentWrite(t *testing.T) {
}()
// Read from the other end.
_, err = io.Copy(ioutil.Discard, c)
_, err = io.Copy(io.Discard, c)
c.Close()
if err != nil {
t.Fatalf("Read: %v", err)
@ -336,7 +335,7 @@ func BenchmarkUpgradeBufferSize(b *testing.B) {
func BenchmarkReadWrite(b *testing.B) {
trial := func(b *testing.B, readConn, writeConn *Conn, msgSize int) {
go func() {
io.Copy(ioutil.Discard, readConn)
io.Copy(io.Discard, readConn)
}()
data := make([]byte, msgSize)
b.ResetTimer()