Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce String method on PortMapping #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ndeloof
Copy link
Contributor

@ndeloof ndeloof commented Jan 16, 2024

This introduce PortMapping.String() for (some) symmetry with ParsePortSpec

nat/nat.go Outdated
@@ -150,6 +150,10 @@ type PortMapping struct {
Binding PortBinding
}

func (p *PortMapping) String() string {
return fmt.Sprintf("%s:%s:%s", p.Binding.HostIP, p.Binding.HostPort, p.Port)
Copy link
Member

Choose a reason for hiding this comment

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

We should use net.JoinHostPort() here, to account for IPv6 addresses; https://pkg.go.dev/net#JoinHostPort

e.g.;

Suggested change
return fmt.Sprintf("%s:%s:%s", p.Binding.HostIP, p.Binding.HostPort, p.Port)
return net.JoinHostPort(p.Binding.HostIP, p.Binding.HostPort+":"+p.Port.Port())

But I need to have a closer look, as there's many possible formats (ports mapped here can also have the protocol (e.g. 80/tcp), which may have to be taken into account here.

And of course we also have PortMap (which is a list of mapped ports) 😞

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I guess HostPort doesn't have the scheme, so maybe that part is not an issue

Copy link
Member

Choose a reason for hiding this comment

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

Do we know if HostIP defaults to 0.0.0.0 (or :: IPv6)? 🤔

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

Successfully merging this pull request may close these issues.

None yet

3 participants