mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-02-05 05:50:08 +08:00
add a helper function to go directly from a string to an AddrInfo (#184)
* add a helper function to go directly from a string to an AddrInfo * Update peer/addrinfo.go Co-authored-by: Will <will.scott@protocol.ai> Co-authored-by: Will <will.scott@protocol.ai>
This commit is contained in:
parent
ca38e17432
commit
11f3c3ac0c
@ -3,6 +3,7 @@ package peer
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
)
|
||||
|
||||
@ -61,6 +62,16 @@ func SplitAddr(m ma.Multiaddr) (transport ma.Multiaddr, id ID) {
|
||||
return transport, id
|
||||
}
|
||||
|
||||
// AddrInfoFromString builds an AddrInfo from the string representation of a Multiaddr
|
||||
func AddrInfoFromString(s string) (*AddrInfo, error) {
|
||||
a, err := multiaddr.NewMultiaddr(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return AddrInfoFromP2pAddr(a)
|
||||
}
|
||||
|
||||
// AddrInfoFromP2pAddr converts a Multiaddr to an AddrInfo.
|
||||
func AddrInfoFromP2pAddr(m ma.Multiaddr) (*AddrInfo, error) {
|
||||
transport, id := SplitAddr(m)
|
||||
|
Loading…
Reference in New Issue
Block a user