feat: add joinHostPort and splitHostPort network functions#477
Open
ricardbejarano wants to merge 1 commit intoMasterminds:masterfrom
Open
feat: add joinHostPort and splitHostPort network functions#477ricardbejarano wants to merge 1 commit intoMasterminds:masterfrom
ricardbejarano wants to merge 1 commit intoMasterminds:masterfrom
Conversation
Fixes Masterminds#472. Adds two new template functions that wrap Go's standard library net.JoinHostPort and net.SplitHostPort: - joinHostPort(host, port): combines host and port into host:port, correctly bracketing IPv6 addresses as [host]:port. - splitHostPort(hostport): splits host:port into a map{host, port}, handling IPv6 bracket notation transparently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #472 in the upstream project (#472).
What
Adds two new template functions to the network category:
joinHostPort host port— wrapsnet.JoinHostPort. Combines a host and port intohost:port, correctly bracketing IPv6 addresses as[host]:port.splitHostPort hostport— wrapsnet.SplitHostPort. Splits ahost:portstring into amap[string]stringwith keyshostandport, handling IPv6 bracket notation transparently.Why
urlJoin/urlParseexist for full URLs, but there was no idiomatic way to construct or parse barehost:portendpoints, which is a common need when templating network configurations (proxies, listeners, upstream addresses). IPv6 addresses require bracket notation that is easy to get wrong manually.Examples
Changes
network.go: implementjoinHostPortandsplitHostPortnetwork_test.go: unit tests covering IPv4, IPv6, and hostname inputsfunctions.go: register both functions in the function map and the non-sandbox listdocs/network.md: documentation for both functionsCHANGELOG.md: entry under unreleased 3.4.0