fix socks proxy without auth

This commit is contained in:
Valentine 2024-01-29 00:07:40 +03:00
parent d45ac95957
commit dbe17fb4d0

View file

@ -143,7 +143,16 @@ func (s *Scraper) SetProxy(proxyAddr string) error {
host := proxyURL.Hostname() host := proxyURL.Hostname()
port := proxyURL.Port() port := proxyURL.Port()
dialSocksProxy, err := proxy.SOCKS5("tcp", host+":"+port, &proxy.Auth{User: username, Password: password}, baseDialer) var auth *proxy.Auth
if username != "" || password != "" {
auth = &proxy.Auth{
User: username,
Password: password,
}
}
dialSocksProxy, err := proxy.SOCKS5("tcp", host+":"+port, auth, baseDialer)
if err != nil { if err != nil {
return errors.New("error creating socks5 proxy :" + err.Error()) return errors.New("error creating socks5 proxy :" + err.Error())
} }