rename getIPAddrList() to getIPAddrs and improve code format

This commit is contained in:
Zeal 2016-06-06 20:56:53 +08:00
parent eb0422cee1
commit d8ecd42868

View File

@ -411,8 +411,8 @@ func (h *httpTransport) Listen(addr string, opts ...ListenOption) (Listener, err
if config == nil {
hosts := []string{addr}
if h, _, e := net.SplitHostPort(addr); e == nil {
if h == "" {
hosts = getIPAddrList()
if len(h) == 0 {
hosts = getIPAddrs()
} else {
hosts = []string{h}
}
@ -457,19 +457,20 @@ func newHTTPTransport(opts ...Option) *httpTransport {
return &httpTransport{opts: options}
}
func getIPAddrList() []string {
func getIPAddrs() []string {
ifaces, err := net.Interfaces()
if err != nil {
return nil
}
var ipAddrlist []string
var ipAddrs []string
for _, i := range ifaces {
if addrs, err := i.Addrs(); err != nil {
addrs, err := i.Addrs()
if err != nil {
continue
} else {
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
@ -488,9 +489,8 @@ func getIPAddrList() []string {
continue
}
ipAddrlist = append(ipAddrlist, ip.String())
ipAddrs = append(ipAddrs, ip.String())
}
}
}
return ipAddrlist
return ipAddrs
}