Closed
Description
net.IP types implement a fmt.Stringer interface which will output the human representation for IPv4 or IPv6 addresses. In particular the IPv6 address follows RFC5952 which will compress/shorten IPv6 addresses as much as possible.
However this isn't always the desired output for an IPv6 address. Sometimes you want a fully expanded IPv6 address for comparability with other systems/languages.
This proposal is to add fmt.Formatter implementation to the IPv6 address so that when the IP address is formatted with the v
verb with a +
flag that the expanded IPv6 address is outputted instead of the compressed version.
Examples:
ip := net.ParseIP("2001:db8::1")
fmt.Printf("%s", ip) // prints "2001:db8::1"
fmt.Printf("%v", ip) // prints "2001:db8::1" (same as %s)
fmt.Printf("%+v", ip) // prints "2001:0db8:0000:0000:0000:0000:0000:0001"
For IPv4 %s
, %v
, %+v
will all be the same.