rename getIPAddrList() to getIPAddrs and improve code format
This commit is contained in:
		| @@ -411,8 +411,8 @@ func (h *httpTransport) Listen(addr string, opts ...ListenOption) (Listener, err | |||||||
| 			if config == nil { | 			if config == nil { | ||||||
| 				hosts := []string{addr} | 				hosts := []string{addr} | ||||||
| 				if h, _, e := net.SplitHostPort(addr); e == nil { | 				if h, _, e := net.SplitHostPort(addr); e == nil { | ||||||
| 					if h == "" { | 					if len(h) == 0 { | ||||||
| 						hosts = getIPAddrList() | 						hosts = getIPAddrs() | ||||||
| 					} else { | 					} else { | ||||||
| 						hosts = []string{h} | 						hosts = []string{h} | ||||||
| 					} | 					} | ||||||
| @@ -457,40 +457,40 @@ func newHTTPTransport(opts ...Option) *httpTransport { | |||||||
| 	return &httpTransport{opts: options} | 	return &httpTransport{opts: options} | ||||||
| } | } | ||||||
|  |  | ||||||
| func getIPAddrList() []string { | func getIPAddrs() []string { | ||||||
| 	ifaces, err := net.Interfaces() | 	ifaces, err := net.Interfaces() | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var ipAddrlist []string | 	var ipAddrs []string | ||||||
|  |  | ||||||
| 	for _, i := range ifaces { | 	for _, i := range ifaces { | ||||||
| 		if addrs, err := i.Addrs(); err != nil { | 		addrs, err := i.Addrs() | ||||||
|  | 		if err != nil { | ||||||
| 			continue | 			continue | ||||||
| 		} else { | 		} | ||||||
| 			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 { | 		for _, addr := range addrs { | ||||||
| 					continue | 			var ip net.IP | ||||||
| 				} | 			switch v := addr.(type) { | ||||||
|  | 			case *net.IPNet: | ||||||
| 				ip = ip.To4() | 				ip = v.IP | ||||||
| 				if ip == nil { | 			case *net.IPAddr: | ||||||
| 					continue | 				ip = v.IP | ||||||
| 				} |  | ||||||
|  |  | ||||||
| 				ipAddrlist = append(ipAddrlist, ip.String()) |  | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			if ip == nil { | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			ip = ip.To4() | ||||||
|  | 			if ip == nil { | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			ipAddrs = append(ipAddrs, ip.String()) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return ipAddrlist | 	return ipAddrs | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user