This repository was archived by the owner on May 25, 2023. It is now read-only.

Description
I'm puzzling over how IPPort and IPPrefix's MarshalText methods should work when their IP is the zero IP but they have a non-zero port/bits.
Currently we return an empty slice, but that doesn't round trip. If you do IPPortFrom(IP{}, 80), MarshalText, and then UnmarshalText, you get a zero IPPort. That is, we lose the 80. Similarly so for IPPrefix.
Options:
- Make MarshalText return an error when there is a zero IP and a non-zero port/prefix. We then lose the nice property that MarshalText never returns an error.
- Make MarshalText return something like
:80 (or invalid IP:80?), and then teach UnmarshalText to handle those inputs. We then lose the nice property that UnmarshalText is identical to ParseIPPort except in its handling of an empty input.
- Do the previous option, and also change ParseIPPort to match UnmarshalText. We then lose the nice property that there is no way to get a zero IP by parsing a textual input, only by constructing one in code.
I'm inclined towards 1, but don't feel strongly. Opinions?
cc @danderson @maisem @bradfitz @mdlayher