Skip to content

net: Expose return values of default implementations of net.Addr.Network() as constants rather than hardcoded strings #11731

Open
@srinathh

Description

@srinathh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions