// TryProxies iterates f over each configured proxy (including "noproxy" and
// "direct" if applicable) until f returns no error or until f returns an
// error that is not equivalent to os.ErrNotExist on a proxy configured
// not to fall back on errors.
//
// TryProxies then returns that final error.
//
// If GOPROXY is set to "off", TryProxies invokes f once with the argument
// "off".
TryProxies iterates f over each configured proxy (including "noproxy" and
"direct" if applicable) until f returns no error or until f returns an
error that is not equivalent to os.ErrNotExist on a proxy configured
not to fall back on errors.

TryProxies then returns that final error.

If GOPROXY is set to "off", TryProxies invokes f once with the argument
"off".
// TryProxies iterates f over each configured proxy ( including " noproxy " and // " direct " if applicable ) until f returns no error or until f returns an // error that is not equivalent to os . ErrNotExist on a proxy configured // not to fall back on errors . // // TryProxies then returns that final error . // // If GOPROXY is set to " off " TryProxies invokes f once with the argument // " off " .
func TryProxies(f func(proxy string) error) error {
	proxies, err := proxyList()
	if err != nil {
		return err
	}
	if len(proxies) == 0 {
		return f("off")
	}
	 Note that errProxyOff, errNoproxy, and errUseProxy are equivalent to
	 ErrNotExist. errUseProxy should only be returned if "noproxy" is the only
	 proxy. errNoproxy should never be returned, since there should always be a
	 more useful error from "noproxy" first.
	const (
		notExistRank = iota
		proxyRank
		directRank
	)
	var bestErr error
	bestErrRank := notExistRank
	for _, proxy := range proxies {
		err := f(proxy.url)
		if err == nil {
			return nil
		}
		isNotExistErr := errors.Is(err, os.ErrNotExist)
		if proxy.url == "direct" || (proxy.url == "noproxy" && err != errUseProxy) {
			bestErr = err
			bestErrRank = directRank
		} else if bestErrRank <= proxyRank && !isNotExistErr {
			bestErr = err
			bestErrRank = proxyRank
		} else if bestErrRank == notExistRank {
			bestErr = err
		}
		if !proxy.fallBackOnError && !isNotExistErr {
			break
		}
	}
	return bestErr
}
func TryProxies ( f func ( proxy string ) error ) error { proxies , err := proxyList ( ) if err != nil { return err } if len ( proxies ) == 0 { return f ( " " ) } const ( notExistRank = iota proxyRank directRank ) var bestErr error bestErrRank := notExistRank for _ , proxy := range proxies { err := f ( proxy . url ) if err == nil { return nil } isNotExistErr := errors . Is ( err , os . ErrNotExist ) if proxy . url == " " || ( proxy . url == " " && err != errUseProxy ) { bestErr = err bestErrRank = directRank } else if bestErrRank <= proxyRank && ! isNotExistErr { bestErr = err bestErrRank = proxyRank } else if bestErrRank == notExistRank { bestErr = err } if ! proxy . fallBackOnError && ! isNotExistErr { break } } return bestErr }
TryProxies iterates f over each configured proxy (including "noproxy" and
"direct" if applicable) until f returns no error or until f returns an
error that is not equivalent to os.ErrNotExist on a proxy configured
not to fall back on errors.
TryProxies iterates f over each configured proxy ( including " noproxy " and " direct " if applicable ) until f returns no error or until f returns an error that is not equivalent to os . ErrNotExist on a proxy configured not to fall back on errors .
// We try to report the most helpful error to the user. "direct" and "noproxy" // errors are best, followed by proxy errors other than ErrNotExist, followed // by ErrNotExist. // // Note that errProxyOff, errNoproxy, and errUseProxy are equivalent to // ErrNotExist. errUseProxy should only be returned if "noproxy" is the only // proxy. errNoproxy should never be returned, since there should always be a // more useful error from "noproxy" first.