Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 11f3c3a

Browse files
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>
1 parent ca38e17 commit 11f3c3a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

peer/addrinfo.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package peer
33
import (
44
"fmt"
55

6+
"github.com/multiformats/go-multiaddr"
67
ma "github.com/multiformats/go-multiaddr"
78
)
89

@@ -61,6 +62,16 @@ func SplitAddr(m ma.Multiaddr) (transport ma.Multiaddr, id ID) {
6162
return transport, id
6263
}
6364

65+
// AddrInfoFromString builds an AddrInfo from the string representation of a Multiaddr
66+
func AddrInfoFromString(s string) (*AddrInfo, error) {
67+
a, err := multiaddr.NewMultiaddr(s)
68+
if err != nil {
69+
return nil, err
70+
}
71+
72+
return AddrInfoFromP2pAddr(a)
73+
}
74+
6475
// AddrInfoFromP2pAddr converts a Multiaddr to an AddrInfo.
6576
func AddrInfoFromP2pAddr(m ma.Multiaddr) (*AddrInfo, error) {
6677
transport, id := SplitAddr(m)

0 commit comments

Comments
 (0)