MCPcopy
hub / github.com/golang/net / FromURL

Function FromURL

proxy/proxy.go:81–110  ·  view source on GitHub ↗

FromURL returns a Dialer given a URL specification and an underlying Dialer for it to make network requests.

(u *url.URL, forward Dialer)

Source from the content-addressed store, hash-verified

79// FromURL returns a Dialer given a URL specification and an underlying
80// Dialer for it to make network requests.
81func FromURL(u *url.URL, forward Dialer) (Dialer, error) {
82 var auth *Auth
83 if u.User != nil {
84 auth = new(Auth)
85 auth.User = u.User.Username()
86 if p, ok := u.User.Password(); ok {
87 auth.Password = p
88 }
89 }
90
91 switch u.Scheme {
92 case "socks5", "socks5h":
93 addr := u.Hostname()
94 port := u.Port()
95 if port == "" {
96 port = "1080"
97 }
98 return SOCKS5("tcp", net.JoinHostPort(addr, port), auth, forward)
99 }
100
101 // If the scheme doesn't match any of the built-in schemes, see if it
102 // was registered by another package.
103 if proxySchemes != nil {
104 if f, ok := proxySchemes[u.Scheme]; ok {
105 return f(u, forward)
106 }
107 }
108
109 return nil, errors.New("proxy: unknown scheme: " + u.Scheme)
110}
111
112var (
113 allProxyEnv = &envOnce{

Callers 2

FromEnvironmentUsingFunction · 0.85
TestFromURLFunction · 0.85

Calls 2

SOCKS5Function · 0.85
NewMethod · 0.80

Tested by 1

TestFromURLFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…