Proxy middleware for gorequests — route a request through a random HTTP(S) or SOCKS proxy from a list, with one
Use()call.
gorequests-proxy is a ClientOverride
middleware for gorequests. Give it a list of proxy URLs and it rewires the
request's transport to dial through one of them, chosen at random — HTTP and
HTTPS proxies via Go's proxy transport, SOCKS proxies via
h12.io/socks.
go get github.com/memclutter/gorequests-proxyRequires Go 1.18+.
Pass a Proxy to the Use() method of a request:
import (
"net/http"
"github.com/memclutter/gorequests"
gorequests_proxy "github.com/memclutter/gorequests-proxy"
)
proxy := &gorequests_proxy.Proxy{
Proxies: []string{
"http://example.com:5554",
"http://user:[email protected]:33333",
"socks5://10.0.0.2:1080",
},
}
err := gorequests.Get("https://api.ipify.org?format=json").
Use(proxy).
ResponseCodeOk(http.StatusOK).
Exec()A fresh proxy is picked at random from the list for each Exec().
| Field | Type | Description |
|---|---|---|
Proxies |
[]string |
Candidate proxy URLs. Entries are trimmed; blank entries are ignored. |
AllowEmpty |
bool |
When true, an empty list is a no-op (the request runs directly). When false (default), an empty list returns an error. |
Each entry is a full URL, with optional inline credentials:
http://host:3128
http://user:pass@host:3128
https://host:8443
socks5://host:1080
socks4://host:1080
Any scheme containing socks is dialed through h12.io/socks; everything else
is treated as an HTTP(S) proxy.
gorequests-proxy recognises the transport installed by
gorequests-retry, so the two
middlewares stack — apply Retry first, then Proxy:
err := gorequests.Get("https://api.example.com/").
Use(&gorequests_retry.Retry{RetryMax: 3}).
Use(proxy).
Exec()Contributions are welcome — see CONTRIBUTING.md for setup, coding conventions, and the commit/PR process. Changes are recorded in CHANGELOG.md.
Released under the MIT License.