There is probably some code here ( https://github.com/golang/go/commit/1ff19201fd898c3e1a0ed5d3458c81c1f062570b) you can lift until go1.8 comes out.
On Mon, Sep 12, 2016 at 8:17 PM Jonathan Yu <jonathan.i...@gmail.com> wrote: > Hi, > > I tried searching Google, but didn't find anything. I'm probably just > missing something obvious here, but I'm relatively new to Go - please bear > with me :) > > In URLs (of the net/url variety), the Host field may be either a hostname > or host/port combination. In the combined host/port case, we can use > net.SplitHostPort to isolate the host/port portions, but if a port isn't > specified, then we'll get an error. > > We can use the same code as in SplitHostPort ("last" to check if the > string contains a colon): > https://github.com/golang/go/blob/master/src/net/ipsock.go#L119 but this > is a bit less convenient than having SplitHostPort return the host directly > (though I understand this may not be changeable without breaking API > compatibility) > > Is there an easier way to say "give me the host/port if the input is > host:port, or host otherwise?" Alternately, some way to check for the error > type might be useful (similar to how os.IsNotExist(err) works) -- my way of > doing it (simply checking for a colon) seems like it'd be problematic with > IPv6 addresses. > > Thanks! > > Jonathan > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.