From a47d916b50a96e7ee6bd08c1fc444f2cc39695a2 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Jan 2017 13:52:49 +0000 Subject: [PATCH] move ip func --- transport/http_transport.go | 42 ++----------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/transport/http_transport.go b/transport/http_transport.go index 2eb74bd8..ce562129 100644 --- a/transport/http_transport.go +++ b/transport/http_transport.go @@ -17,6 +17,7 @@ import ( "sync" "time" + maddr "github.com/micro/misc/lib/addr" mls "github.com/micro/misc/lib/tls" ) @@ -56,45 +57,6 @@ type httpTransportListener struct { listener net.Listener } -func getIPAddrs() []string { - ifaces, err := net.Interfaces() - if err != nil { - return nil - } - - var ipAddrs []string - - for _, i := range ifaces { - addrs, err := i.Addrs() - if err != nil { - continue - } - - for _, addr := range addrs { - var ip net.IP - switch v := addr.(type) { - case *net.IPNet: - ip = v.IP - case *net.IPAddr: - ip = v.IP - } - - if ip == nil { - continue - } - - ip = ip.To4() - if ip == nil { - continue - } - - ipAddrs = append(ipAddrs, ip.String()) - } - } - - return ipAddrs -} - func listen(addr string, fn func(string) (net.Listener, error)) (net.Listener, error) { // host:port || host:min-max parts := strings.Split(addr, ":") @@ -479,7 +441,7 @@ func (h *httpTransport) Listen(addr string, opts ...ListenOption) (Listener, err // check if its a valid host:port if host, _, err := net.SplitHostPort(addr); err == nil { if len(host) == 0 { - hosts = getIPAddrs() + hosts = maddr.IPs() } else { hosts = []string{host} }