Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
net: SplitHostPort has inconsistent error conditions #18040
In net.SplitHostPort, giving a string with a port defined, but no hostname (e.g. ":80"), results in an empty host, a port and an empty error. Providing a hostname (or IP) with no port (e.g. "foo.bar.com"), results in an error.
I would think that both of these scenarios should behave in the same way: either both should return an error, or both should return an empty value and no error.
I think it's pretty consistent: if there's no colon, it returns an error: https://play.golang.org/p/77zhzVOa9g
In any case, we've had this same behavior for 4+ years now, so I don't think we want to change it now.
The new URL.Port and URL.Hostname methods in Go 1.8 should help with this, though, since I think they're more likely doing what you want.