apply go tools cleanup
This commit is contained in:
@ -14,15 +14,15 @@ func GetTransport(proxy string) (http.RoundTripper, error) {
|
||||
if proxy == "" {
|
||||
return http.DefaultTransport, nil
|
||||
}
|
||||
proxyUrl, err := url.Parse(proxy)
|
||||
proxyURL, err := url.Parse(proxy)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse proxyUrl, url:%s, err: %w", proxy, err)
|
||||
}
|
||||
if proxyUrl.Host == "unix" && proxyUrl.Scheme == "socks5" &&
|
||||
len(proxyUrl.Path) > 1 /* Path cannot be empty or just / */ {
|
||||
return unixSocks5Proxy(proxyUrl)
|
||||
if proxyURL.Host == "unix" && proxyURL.Scheme == "socks5" &&
|
||||
len(proxyURL.Path) > 1 /* Path cannot be empty or just / */ {
|
||||
return unixSocks5Proxy(proxyURL)
|
||||
}
|
||||
return proxyTcp(proxyUrl)
|
||||
return proxyTCP(proxyURL)
|
||||
}
|
||||
|
||||
type forwardDialer func(ctx context.Context, network, address string) (net.Conn, error)
|
||||
@ -34,14 +34,14 @@ func (d forwardDialer) Dial(network, address string) (net.Conn, error) {
|
||||
panic("Dial should not be called")
|
||||
}
|
||||
|
||||
func unixSocks5Proxy(proxyUrl *url.URL) (http.RoundTripper, error) {
|
||||
func unixSocks5Proxy(proxyURL *url.URL) (http.RoundTripper, error) {
|
||||
trans := defaultTransport().Clone()
|
||||
if trans.DialContext == nil {
|
||||
panic("DefaultTransport has nil DialContext")
|
||||
}
|
||||
var auth *proxy.Auth
|
||||
username := proxyUrl.User.Username()
|
||||
password, _ := proxyUrl.User.Password()
|
||||
username := proxyURL.User.Username()
|
||||
password, _ := proxyURL.User.Password()
|
||||
// Both username and password should have atleast one char
|
||||
if username != "" && password != "" {
|
||||
auth = &proxy.Auth{
|
||||
@ -49,9 +49,9 @@ func unixSocks5Proxy(proxyUrl *url.URL) (http.RoundTripper, error) {
|
||||
Password: password,
|
||||
}
|
||||
}
|
||||
dialer, err := proxy.SOCKS5("unix", proxyUrl.Path, auth, forwardDialer(trans.DialContext))
|
||||
dialer, err := proxy.SOCKS5("unix", proxyURL.Path, auth, forwardDialer(trans.DialContext))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to make socks proxy, url: %s, err: %w", proxyUrl, err)
|
||||
return nil, fmt.Errorf("failed to make socks proxy, url: %s, err: %w", proxyURL, err)
|
||||
}
|
||||
ctxDialer, ok := dialer.(proxy.ContextDialer)
|
||||
if !ok {
|
||||
@ -62,9 +62,9 @@ func unixSocks5Proxy(proxyUrl *url.URL) (http.RoundTripper, error) {
|
||||
return trans, nil
|
||||
}
|
||||
|
||||
func proxyTcp(proxyUrl *url.URL) (http.RoundTripper, error) {
|
||||
func proxyTCP(proxyURL *url.URL) (http.RoundTripper, error) {
|
||||
trans := defaultTransport().Clone()
|
||||
trans.Proxy = http.ProxyURL(proxyUrl)
|
||||
trans.Proxy = http.ProxyURL(proxyURL)
|
||||
return trans, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user