Skip to content

Commit

Permalink
Show IPv6 addresses with [ and ]
Browse files Browse the repository at this point in the history
So that users can open IPv6 URLs on web browsers.
  • Loading branch information
yudai committed Aug 23, 2015
1 parent a0f6e8d commit 5d2cdd2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,13 @@ func listAddresses() (addresses []string) {
for _, ifAddr := range ifAddrs {
switch v := ifAddr.(type) {
case *net.IPNet:
addresses = append(addresses, v.IP.String())
if v.IP.To4() == nil {
addresses = append(addresses, "["+v.IP.String()+"]")

This comment has been minimized.

Copy link
@ahmetb

ahmetb Aug 23, 2015

you should probably use net.JoinHostPort and it should give you addrs with [ ] already. no need to duplicate the logic. :)

} else {
addresses = append(addresses, v.IP.String())
}
case *net.IPAddr:
addresses = append(addresses, v.IP.To16().String())
addresses = append(addresses, v.IP.To4().String())
addresses = append(addresses, v.IP.String())
}
}
}
Expand Down

0 comments on commit 5d2cdd2

Please # to comment.