feishu
feishu copied to clipboard
是否可以支持proxy代理方式
非常感谢大佬的分享,因为应用是内网部署的不能直接访问公网,请问是否可以支持通过proxy代理的功能,比如squid
本项目里面是用 github.com/go-resty/resty/v2 发送的请求,我查看 API,看到
// SetProxy method sets the Proxy URL and Port for Resty client.
// client.SetProxy("http://proxyserver:8888")
//
// OR Without this `SetProxy` method, you could also set Proxy via environment variable.
//
// Refer to godoc `http.ProxyFromEnvironment`.
func (c *Client) SetProxy(proxyURL string) *Client
查看 http.ProxyFromEnvironment ,找到
// ProxyFromEnvironment returns the URL of the proxy to use for a
// given request, as indicated by the environment variables
// HTTP_PROXY, HTTPS_PROXY and NO_PROXY (or the lowercase versions
// thereof). HTTPS_PROXY takes precedence over HTTP_PROXY for https
// requests.
//
// The environment values may be either a complete URL or a
// "host[:port]", in which case the "http" scheme is assumed.
// The schemes "http", "https", and "socks5" are supported.
// An error is returned if the value is a different form.
//
// A nil URL and nil error are returned if no proxy is defined in the
// environment, or a proxy should not be used for the given request,
// as defined by NO_PROXY.
//
// As a special case, if req.URL.Host is "localhost" (with or without
// a port number), then a nil URL and nil error will be returned.
func ProxyFromEnvironment(req *Request) (*url.URL, error)
所以,你可以试下通过环境变量 HTTP_PROXY, HTTPS_PROXY ,来设置 proxy 代理