Last active
September 20, 2021 07:41
-
-
Save imthaghost/14dc8f3b83d121b9268c620c1467944e to your computer and use it in GitHub Desktop.
SmartProxy initializes and returns a proxy function for use in a Transport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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