Implement fmt.Stringer for PeerInfo

This commit is contained in:
Matt Joiner 2019-03-08 15:16:03 +11:00
parent d2a21b6d4a
commit d9cfa764ad

View File

@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-peer"
ma "github.com/multiformats/go-multiaddr"
)
@ -18,6 +18,12 @@ type PeerInfo struct {
Addrs []ma.Multiaddr
}
var _ fmt.Stringer = PeerInfo{}
func (pi PeerInfo) String() string {
return fmt.Sprintf("{%v: %v}", pi.ID, pi.Addrs)
}
var ErrInvalidAddr = fmt.Errorf("invalid p2p multiaddr")
func InfoFromP2pAddr(m ma.Multiaddr) (*PeerInfo, error) {