mirror of
https://github.com/waku-org/go-multiaddr.git
synced 2025-02-23 11:38:20 +00:00
use NewComponent in FromIP
This allows us to do less string-parsing.
This commit is contained in:
parent
03e871bdbe
commit
5bd241dcaf
@ -68,14 +68,16 @@ func parseBasicNetMaddr(maddr ma.Multiaddr) (net.Addr, error) {
|
||||
|
||||
// FromIP converts a net.IP type to a Multiaddr.
|
||||
func FromIP(ip net.IP) (ma.Multiaddr, error) {
|
||||
var proto string
|
||||
switch {
|
||||
case ip.To4() != nil:
|
||||
return ma.NewMultiaddr("/ip4/" + ip.String())
|
||||
proto = "ip4"
|
||||
case ip.To16() != nil:
|
||||
return ma.NewMultiaddr("/ip6/" + ip.String())
|
||||
proto = "ip6"
|
||||
default:
|
||||
return nil, errIncorrectNetAddr
|
||||
}
|
||||
return ma.NewComponent(proto, ip.String())
|
||||
}
|
||||
|
||||
// DialArgs is a convenience function returning arguments for use in net.Dial
|
||||
|
Loading…
x
Reference in New Issue
Block a user