Skip to content

Commit

Permalink
stop using the deprecated io/ioutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Aug 16, 2022
1 parent a91bf7b commit ad35f63
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 65 deletions.
3 changes: 1 addition & 2 deletions examples/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
mrand "math/rand"

Expand Down Expand Up @@ -173,7 +172,7 @@ func runSender(ctx context.Context, ha host.Host, targetPeer string) {
return
}

out, err := ioutil.ReadAll(s)
out, err := io.ReadAll(s)
if err != nil {
log.Println(err)
return
Expand Down
10 changes: 4 additions & 6 deletions examples/ipfs-camp-2019/05-Discovery/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package main

import (
"bufio"
"context"
"fmt"
"io"
"os"

"context"

"io/ioutil"

"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/protocol"
Expand All @@ -17,7 +15,7 @@ import (
const chatProtocol = protocol.ID("/libp2p/chat/1.0.0")

func chatHandler(s network.Stream) {
data, err := ioutil.ReadAll(s)
data, err := io.ReadAll(s)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
Expand All @@ -38,7 +36,7 @@ func chatSend(msg string, s network.Stream) error {
return err
}
s.Close()
data, err := ioutil.ReadAll(s)
data, err := io.ReadAll(s)
if err != nil {
return err
}
Expand Down
10 changes: 4 additions & 6 deletions examples/ipfs-camp-2019/06-Pubsub/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package main

import (
"bufio"
"context"
"fmt"
"io"
"os"

"context"

"io/ioutil"

"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/protocol"
Expand All @@ -19,7 +17,7 @@ const chatProtocol = protocol.ID("/libp2p/chat/1.0.0")
// TODO: Replace this handler with a function that handles message from a
// pubsub Subscribe channel.
func chatHandler(s network.Stream) {
data, err := ioutil.ReadAll(s)
data, err := io.ReadAll(s)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
Expand All @@ -42,7 +40,7 @@ func chatSend(msg string, s network.Stream) error {
return err
}
s.Close()
data, err := ioutil.ReadAll(s)
data, err := io.ReadAll(s)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions examples/multipro/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"log"

"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"

"github.com/gogo/protobuf/proto"
uuid "github.com/google/uuid"
"github.com/google/uuid"
pb "github.com/libp2p/go-libp2p/examples/multipro/pb"
)

Expand Down Expand Up @@ -39,7 +39,7 @@ func (e *EchoProtocol) onEchoRequest(s network.Stream) {

// get request data
data := &pb.EchoRequest{}
buf, err := ioutil.ReadAll(s)
buf, err := io.ReadAll(s)
if err != nil {
s.Reset()
log.Println(err)
Expand Down Expand Up @@ -93,7 +93,7 @@ func (e *EchoProtocol) onEchoRequest(s network.Stream) {
func (e *EchoProtocol) onEchoResponse(s network.Stream) {

data := &pb.EchoResponse{}
buf, err := ioutil.ReadAll(s)
buf, err := io.ReadAll(s)
if err != nil {
s.Reset()
log.Println(err)
Expand Down
6 changes: 3 additions & 3 deletions examples/multipro/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"log"

"github.com/libp2p/go-libp2p-core/host"
Expand Down Expand Up @@ -36,7 +36,7 @@ func (p *PingProtocol) onPingRequest(s network.Stream) {

// get request data
data := &p2p.PingRequest{}
buf, err := ioutil.ReadAll(s)
buf, err := io.ReadAll(s)
if err != nil {
s.Reset()
log.Println(err)
Expand Down Expand Up @@ -88,7 +88,7 @@ func (p *PingProtocol) onPingRequest(s network.Stream) {
// remote ping response handler
func (p *PingProtocol) onPingResponse(s network.Stream) {
data := &p2p.PingResponse{}
buf, err := ioutil.ReadAll(s)
buf, err := io.ReadAll(s)
if err != nil {
s.Reset()
log.Println(err)
Expand Down
4 changes: 2 additions & 2 deletions examples/routed-echo/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"sync"
Expand Down Expand Up @@ -47,7 +47,7 @@ func getLocalPeerInfo() []peer.AddrInfo {
if err != nil {
log.Fatalln(err)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
Expand Down
3 changes: 1 addition & 2 deletions examples/routed-echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
mrand "math/rand"

Expand Down Expand Up @@ -173,7 +172,7 @@ func main() {
log.Fatalln(err)
}

out, err := ioutil.ReadAll(s)
out, err := io.ReadAll(s)
if err != nil {
log.Fatalln(err)
}
Expand Down
5 changes: 2 additions & 3 deletions p2p/host/basic/basic_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"reflect"
"strings"
"sync"
Expand Down Expand Up @@ -490,7 +489,7 @@ func TestProtoDowngrade(t *testing.T) {
connectedOn := make(chan protocol.ID)
h2.SetStreamHandler("/testing/1.0.0", func(s network.Stream) {
defer s.Close()
result, err := ioutil.ReadAll(s)
result, err := io.ReadAll(s)
assert.NoError(t, err)
assert.Equal(t, string(result), "bar")
connectedOn <- s.Protocol()
Expand All @@ -511,7 +510,7 @@ func TestProtoDowngrade(t *testing.T) {
h2.RemoveStreamHandler("/testing/1.0.0")
h2.SetStreamHandler("/testing", func(s network.Stream) {
defer s.Close()
result, err := ioutil.ReadAll(s)
result, err := io.ReadAll(s)
assert.NoError(t, err)
assert.Equal(t, string(result), "foo")
connectedOn <- s.Protocol()
Expand Down
3 changes: 1 addition & 2 deletions p2p/host/peerstore/pstoreds/ds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pstoreds

import (
"context"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -106,7 +105,7 @@ func BenchmarkDsPeerstore(b *testing.B) {
//
//lint:ignore U1000 disabled for now
func badgerStore(tb testing.TB) (ds.Batching, func()) {
dataPath, err := ioutil.TempDir(os.TempDir(), "badger")
dataPath, err := os.MkdirTemp(os.TempDir(), "badger")
if err != nil {
tb.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/muxer/yamux/transport.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package yamux

import (
"io/ioutil"
"io"
"math"
"net"

Expand All @@ -21,7 +21,7 @@ func init() {
// totally unacceptable.
config.MaxStreamWindowSize = uint32(16 * 1024 * 1024)
// don't spam
config.LogOutput = ioutil.Discard
config.LogOutput = io.Discard
// We always run over a security transport that buffers internally
// (i.e., uses a block cipher).
config.ReadBufSize = 0
Expand Down
4 changes: 2 additions & 2 deletions p2p/net/swarm/swarm_net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package swarm_test
import (
"context"
"fmt"
"io/ioutil"
"io"
"testing"
"time"

Expand Down Expand Up @@ -115,7 +115,7 @@ func TestNetworkOpenStream(t *testing.T) {
defer close(done)
defer s.Close()

buf, err := ioutil.ReadAll(s)
buf, err := io.ReadAll(s)
if err != nil {
t.Error(err)
return
Expand Down
3 changes: 1 addition & 2 deletions p2p/protocol/internal/circuitv1-deprecated/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net"
"testing"
"time"
Expand Down Expand Up @@ -191,7 +190,7 @@ func TestRelayReset(t *testing.T) {

close(ready)

_, err = ioutil.ReadAll(con)
_, err = io.ReadAll(con)
if err == nil {
t.Fatal("expected error for reset relayed connection")
}
Expand Down
6 changes: 3 additions & 3 deletions p2p/protocol/internal/circuitv1-deprecated/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"testing"
"time"

Expand Down Expand Up @@ -87,7 +87,7 @@ func TestFullAddressTransportDial(t *testing.T) {
t.Fatal(err)
}

data, err := ioutil.ReadAll(s)
data, err := io.ReadAll(s)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestSpecificRelayTransportDial(t *testing.T) {
t.Fatal(err)
}

data, err := ioutil.ReadAll(s)
data, err := io.ReadAll(s)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions p2p/security/noise/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package noise
import (
"context"
"io"
"io/ioutil"
"math/rand"
"net"
"testing"
Expand Down Expand Up @@ -178,7 +177,7 @@ func benchDataTransfer(b *benchenv, dataSize int64, m testMode) {
case readBufferLtPlainText:
rbuf = make([]byte, len(plainTextBufs[i])-2)
}
writeTos[i] = &discardWithBuffer{rbuf, ioutil.Discard}
writeTos[i] = &discardWithBuffer{rbuf, io.Discard}
}

b.ResetTimer()
Expand Down
4 changes: 2 additions & 2 deletions p2p/security/tls/cmd/tlsdiag/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"io"
"net"
"time"

Expand Down Expand Up @@ -54,7 +54,7 @@ func StartClient() error {
return err
}
fmt.Printf("Authenticated server: %s\n", sconn.RemotePeer().Pretty())
data, err := ioutil.ReadAll(sconn)
data, err := io.ReadAll(sconn)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/transport/quic/cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"crypto/rand"
"fmt"
"io/ioutil"
"io"
"log"
"os"

Expand Down Expand Up @@ -62,7 +62,7 @@ func run(raddr string, p string) error {
if err := str.CloseWrite(); err != nil {
return err
}
data, err := ioutil.ReadAll(str)
data, err := io.ReadAll(str)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/transport/quic/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"crypto/rand"
"fmt"
"io/ioutil"
"io"
"log"
"os"

Expand Down Expand Up @@ -67,7 +67,7 @@ func handleConn(conn tpt.CapableConn) error {
if err != nil {
return err
}
data, err := ioutil.ReadAll(str)
data, err := io.ReadAll(str)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit ad35f63

Please sign in to comment.