func (pc *ProxyConfig) useProxy(addr string) bool {
	if len(addr) == 0 {
		return true
	}
	host, _, err := net.SplitHostPort(addr)
	if err != nil {
		return false
	}
	if host == "localhost" {
		return false
	}
	ip := net.ParseIP(host)
	if ip != nil && ip.IsLoopback() {
		return false
	}

	if pc.noProxy == "*" {
		return false
	}

	addr = strings.ToLower(strings.TrimSpace(addr))
	if hasPort(addr) {
		addr = addr[:strings.LastIndex(addr, ":")]
	}

	for _, p := range strings.Split(pc.noProxy, ",") {
		p = strings.ToLower(strings.TrimSpace(p))
		if len(p) == 0 {
			continue
		}
		if hasPort(p) {
			p = p[:strings.LastIndex(p, ":")]
		}
		if addr == p {
			return false
		}
		if p[0] == '.' && (strings.HasSuffix(addr, p) || addr == p[1:]) {
			// no_proxy ".foo.com" matches "bar.foo.com" or "foo.com"
			return false
		}
		if p[0] != '.' && strings.HasSuffix(addr, p) && addr[len(addr)-len(p)-1] == '.' {
			// no_proxy "foo.com" matches "bar.foo.com"
			return false
		}
		if _, net, err := net.ParseCIDR(p); ip != nil && err == nil && net.Contains(ip) {
			return false
		}
	}
	return true
}
// useProxy reports whether requests to addr should use a proxy,
// according to the NoProxy value of the proxy setting.
// addr is always a canonicalAddr with a host and port.
// (Implementation copied from net/http.useProxy.)
useProxy reports whether requests to addr should use a proxy,
according to the NoProxy value of the proxy setting.
addr is always a canonicalAddr with a host and port.
(Implementation copied from net/http.useProxy.)
// useProxy reports whether requests to addr should use a proxy // according to the NoProxy value of the proxy setting . // addr is always a canonicalAddr with a host and port . // ( Implementation copied from net / http . useProxy . )
func (pc *ProxyConfig) useProxy(addr string) bool {
	if len(addr) == 0 {
		return true
	}
	host, _, err := net.SplitHostPort(addr)
	if err != nil {
		return false
	}
	if host == "localhost" {
		return false
	}
	ip := net.ParseIP(host)
	if ip != nil && ip.IsLoopback() {
		return false
	}
	if pc.noProxy == "*" {
		return false
	}
	addr = strings.ToLower(strings.TrimSpace(addr))
	if hasPort(addr) {
		addr = addr[:strings.LastIndex(addr, ":")]
	}
	for _, p := range strings.Split(pc.noProxy, ",") {
		p = strings.ToLower(strings.TrimSpace(p))
		if len(p) == 0 {
			continue
		}
		if hasPort(p) {
			p = p[:strings.LastIndex(p, ":")]
		}
		if addr == p {
			return false
		}
		if p[0] == '.' && (strings.HasSuffix(addr, p) || addr == p[1:]) {
			return false
		}
		if p[0] != '.' && strings.HasSuffix(addr, p) && addr[len(addr)-len(p)-1] == '.' {
			return false
		}
		if _, net, err := net.ParseCIDR(p); ip != nil && err == nil && net.Contains(ip) {
			return false
		}
	}
	return true
}
func ( pc * ProxyConfig ) useProxy ( addr string ) bool { if len ( addr ) == 0 { return true } host , _ , err := net . SplitHostPort ( addr ) if err != nil { return false } if host == " " { return false } ip := net . ParseIP ( host ) if ip != nil && ip . IsLoopback ( ) { return false } if pc . noProxy == " " { return false } addr = strings . ToLower ( strings . TrimSpace ( addr ) ) if hasPort ( addr ) { addr = addr [ : strings . LastIndex ( addr , " " ) ] } for _ , p := range strings . Split ( pc . noProxy , " " ) { p = strings . ToLower ( strings . TrimSpace ( p ) ) if len ( p ) == 0 { continue } if hasPort ( p ) { p = p [ : strings . LastIndex ( p , " " ) ] } if addr == p { return false } if p [ 0 ] == '.' && ( strings . HasSuffix ( addr , p ) || addr == p [ 1 : ] ) { return false } if p [ 0 ] != '.' && strings . HasSuffix ( addr , p ) && addr [ len ( addr ) - len ( p ) - 1 ] == '.' { return false } if _ , net , err := net . ParseCIDR ( p ) ; ip != nil && err == nil && net . Contains ( ip ) { return false } } return true }
useProxy reports whether requests to addr should use a proxy,
according to the NoProxy value of the proxy setting.
useProxy reports whether requests to addr should use a proxy according to the NoProxy value of the proxy setting .
// no_proxy ".foo.com" matches "bar.foo.com" or "foo.com" // no_proxy "foo.com" matches "bar.foo.com"