net: Expose return values of default implementations of net.Addr.Network() as constants rather than hardcoded strings #11731
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Currently the default implementations of net.Addr.Network() functions in the net package return hard-coded strings representing the network type as below. This means that callers wanting to check the return value of these functions also have to hard-code these in their own code with the possibilities of typos leading to possibility of bugs.
IPAddr.Network() : "ip"
IPNet.Network() : "ip+net"
TCPAddr.Network() : "tcp"
UDPAddr.Network() : "udp"
UnixAddr.Network() : "unix" or "unixgram" or "unixpacket"
If we expose these default return strings as package constants and have functions use the constants instead of hard-coded strings, callers can compare function return values against constants and be protected against these types of bugs. This would also be fully backwards-compatible.
A block of constants will also serve as a useful single point of reference in the documentation for these functions as currently we need to jump around the documentation to understand what each implementation returns.
Happy to work out a CL for this
The text was updated successfully, but these errors were encountered: