Skip to content

Instantly share code, notes, and snippets.

@imthaghost
Last active September 20, 2021 07:41
Show Gist options
  • Save imthaghost/14dc8f3b83d121b9268c620c1467944e to your computer and use it in GitHub Desktop.
Save imthaghost/14dc8f3b83d121b9268c620c1467944e to your computer and use it in GitHub Desktop.
SmartProxy initializes and returns a proxy function for use in a Transport
// SmartProxy initializes and returns a proxy function for use in a Transport
func SmartProxy() func(*http.Request) (*url.URL, error) {
// base url
base := "https://%s:%s@%s"
// fill credentials into url
rawUrl := fmt.Sprintf(base, <YOUR_SMARTPROXY_USERNAME>, <YOUR_SMARTPROXY_PASSWORD>, "gate.dc.smartproxy.com:20000")
// parse proxy url
proxyUrl, err := url.Parse(rawUrl)
if err != nil {
fmt.Println("invalid url to parse when creating proxy transport. err: ", err)
return nil
}
// setup proxy transport
proxy := http.ProxyURL(proxyUrl)
return proxy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment