Skip to content

nat: SortPortMap: don't require PortMap as argument - #145

Merged
austinvazquez merged 2 commits into
docker:mainfrom
thaJeztah:nat_cleanups_2
Aug 11, 2025
Merged

nat: SortPortMap: don't require PortMap as argument#145
austinvazquez merged 2 commits into
docker:mainfrom
thaJeztah:nat_cleanups_2

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

nat: SortPortMap: don't require PortMap as argument

The PortMap type is equivalent to a map[Port][]PortBinding, but
the SortPortMap only accepted a PortMap. Update the signature to
accept either a PortMap or a map[Port][]PortBinding.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

The `PortMap` type is equivalent to a `map[Port][]PortBinding`, but
the `SortPortMap` only accepted a `PortMap`. Update the signature to
accept either a `PortMap` or a `map[Port][]PortBinding`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The `SortPortMap` function no longer requires a PortMap, and
can accept either a `PortMap` or a `map[Port][]PortBinding`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztah requested a review from Copilot August 11, 2025 13:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the SortPortMap function signature to accept a generic map[Port][]PortBinding instead of the specific PortMap type, making the function more flexible while maintaining the same functionality.

  • Changed function signature from PortMap to map[Port][]PortBinding
  • Updated test to use the generic map type instead of PortMap
  • Simplified map access by removing unnecessary type casting

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
nat/sort.go Updated SortPortMap function signature to accept generic map type
nat/sort_test.go Updated test to use generic map type and simplified map access

Comment thread nat/sort_test.go
"9999/tcp": []PortBinding{{HostIP: "0.0.0.0", HostPort: "40000"}},
portMap := map[Port][]PortBinding{
"22/tcp": {{}},
"8000/tcp": {{}},

Copilot AI Aug 11, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The empty PortBinding struct {{}} could be written more clearly as {PortBinding{}} to make it explicit that you're creating a slice containing one empty PortBinding.

Suggested change
"8000/tcp": {{}},
"8000/tcp": {PortBinding{}},

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"unconvert" doesn't agree; unneeded type conversion

Comment thread nat/sort_test.go
Comment on lines +54 to +57
"22/tcp": {{}},
"8000/tcp": {{}},
"8443/tcp": {},
"6379/tcp": {{}, {HostIP: "0.0.0.0", HostPort: "32749"}},

Copilot AI Aug 11, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The empty PortBinding struct {{}} could be written more clearly as {PortBinding{}} to make it explicit that you're creating a slice containing one empty PortBinding.

Suggested change
"22/tcp": {{}},
"8000/tcp": {{}},
"8443/tcp": {},
"6379/tcp": {{}, {HostIP: "0.0.0.0", HostPort: "32749"}},
"22/tcp": {PortBinding{}},
"8000/tcp": {PortBinding{}},
"8443/tcp": {},
"6379/tcp": {PortBinding{}, {HostIP: "0.0.0.0", HostPort: "32749"}},

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"unconvert" doesn't agree; unneeded type conversion

Comment thread nat/sort_test.go
Comment on lines +54 to +57
"22/tcp": {{}},
"8000/tcp": {{}},
"8443/tcp": {},
"6379/tcp": {{}, {HostIP: "0.0.0.0", HostPort: "32749"}},

Copilot AI Aug 11, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The first empty PortBinding struct {} could be written more clearly as PortBinding{} to make it explicit that you're creating an empty PortBinding.

Suggested change
"22/tcp": {{}},
"8000/tcp": {{}},
"8443/tcp": {},
"6379/tcp": {{}, {HostIP: "0.0.0.0", HostPort: "32749"}},
"22/tcp": {PortBinding{}},
"8000/tcp": {PortBinding{}},
"8443/tcp": {},
"6379/tcp": {PortBinding{}, {HostIP: "0.0.0.0", HostPort: "32749"}},

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"unconvert" doesn't agree; unneeded type conversion

@thaJeztah

Copy link
Copy Markdown
Member Author

@austinvazquez ptal (opening some PRs in smaller steps for visibility; at least one more coming 😂)

@austinvazquez
austinvazquez merged commit fa986a4 into docker:main Aug 11, 2025
13 checks passed
@thaJeztah
thaJeztah deleted the nat_cleanups_2 branch August 11, 2025 15:57
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.

3 participants