Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

add ToIP to complement ToNetAddr #64

Merged
merged 1 commit into from
Feb 26, 2020

Conversation

willscott
Copy link
Contributor

The specific implementations of net.Addr are internal implementation details of this package, and a downstream consumer shouldn't relay on the internal use of net.IPAddr / net.TCPAddr to implement that interface for direct extraction of IP. The consumer would instead need to go through a round of string conversion to retrieve IP safely. Adding an IP extraction function to the interface here will allow the IP to be retrieved more efficiently.

The specific implementations of net.Addr are internal implementation
details of this package, and a downstream consumner shouldn't relay on
the internal use of net.IPAddr / net.TCPAddr to implement that interface
for direct extraction of IP. The consumer would instead need to go through
a round of string conversion to retreive IP safely. Adding an IP extraction
function to the interface here will allow the IP to be retreived more
efficiently.
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say that users shouldn't assume, e.g., that a TCP address will map to a net.TCPAddr, etc. The go standard library relies on this all over the place.

However, this is definitely a useful helper function.

@Stebalien Stebalien merged commit 201fa11 into multiformats:master Feb 26, 2020
@hsanjuan
Copy link
Contributor

Might also use a ToPort() one :)

@Stebalien
Copy link
Member

I'd expect in that case we'd just use ToNetAddr. This is more the "I don't care what protocol we're using, who am I talking to" case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants