I'm trying to use the http proxy code here
proxyUrl := url.Parse(strings.Replace("%v", RandomProxyAddress()))
http.DefaultTransport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
Tells me there are too many arguments in the url.Parse
But when I try
proxyUrl := url.Parse(RandomProxyAddress())
http.DefaultTransport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
I get ./main.go:138: multiple-value url.Parse() in single-value context
When I tried a string replace it also tells me too many varibles. Not sure how to get my proxy to work with the url.Parse
Firstly, url.Parse returns two variables, a URL and an error, as per the docs here.
Secondly, instead of strings.Replace
you probably meant to use fmt.Sprintf("%v", RandomProxyAddress())
, assuming RandomProxyAddress()
returns a string, or something that formats into the string you want. So all in all, you should have:
addr := fmt.Sprintf("%v", RandomProxyAddress())
proxyURL, err := url.Parse(addr)
if err != nil {
log.Println(err)
}
That said, the fmt.Sprintf
would be unnecessary if RandomProxyAddress()
already returns a string. Check the docs for fmt
and fmt.Sprintf
. And if you really did mean to use strings.Replace
, notice that it requires four arguments, not two.