Documentation ¶
Index ¶
- func IsMarked(header http.Header) bool
- func IsNegligibleError(err error) bool
- func IsProxyDialError(err error) bool
- func Proxy(w http.ResponseWriter, r *http.Request, host string, options ...ProxyOption) error
- func ProxyToUrl(w http.ResponseWriter, r *http.Request, targetUrl *url.URL) (err error)
- func ProxyWithGin(ctx *gin.Context, host string, options ...ProxyOption) error
- type ProxyOption
- func WithErrorLogger(errorLogger *log.Logger) ProxyOption
- func WithExtraQueryParams(extraQueryParams map[string][]string) ProxyOption
- func WithModifyResponse(modifyResponse func(*http.Response) error) ProxyOption
- func WithOverrideQueryParams(overrideQueryParams map[string][]string) ProxyOption
- func WithPolyfillHeaders(polyfillHeaders bool) ProxyOption
- func WithRequestUrlPath(requestUrlPath *string) ProxyOption
- func WithScheme(scheme string) ProxyOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNegligibleError ¶ added in v3.0.900
IsNegligibleError 是否是可忽略的代理error?
PS: 如果返回值为true,说明请求已经结束了,无需再响应内容给http客户端了.
func IsProxyDialError ¶ added in v3.0.23
IsProxyDialError 代理请求返回的error,是否是因为dial目标地址失败?
func Proxy ¶
func Proxy(w http.ResponseWriter, r *http.Request, host string, options ...ProxyOption) error
Proxy 代理请求(反向代理,请求转发).
调用此方法就行请求转发前,按照实际场景可以: (1) POST请求,覆盖 request body; (2) 变更请求头(request header).
@param w e.g.ctx.Writer @param r e.g.ctx.Request @param host e.g."127.0.0.1:12345" @param options optional
func ProxyToUrl ¶ added in v3.0.73
ProxyToUrl
项目实战:用 Go 创建一个简易负载均衡器
https://mp.weixin.qq.com/s/pe0CQa3tdrUmC86OSRBNeg
@param targetUrl 可以是 url.Parse() 的返回值
func ProxyWithGin ¶
func ProxyWithGin(ctx *gin.Context, host string, options ...ProxyOption) error
Types ¶
type ProxyOption ¶
type ProxyOption func(opts *proxyOptions)
func WithErrorLogger ¶
func WithErrorLogger(errorLogger *log.Logger) ProxyOption
func WithExtraQueryParams ¶ added in v3.0.33
func WithExtraQueryParams(extraQueryParams map[string][]string) ProxyOption
WithExtraQueryParams
PS: (1) WithOverrideQueryParams 和 WithExtraQueryParams 只能二选一. (2) 值不用进行编码处理.
func WithModifyResponse ¶ added in v3.0.73
func WithModifyResponse(modifyResponse func(*http.Response) error) ProxyOption
func WithOverrideQueryParams ¶ added in v3.0.33
func WithOverrideQueryParams(overrideQueryParams map[string][]string) ProxyOption
WithOverrideQueryParams
PS: (1) WithOverrideQueryParams 和 WithExtraQueryParams 只能二选一. (2) 值不用进行编码处理.
func WithPolyfillHeaders ¶
func WithPolyfillHeaders(polyfillHeaders bool) ProxyOption
func WithRequestUrlPath ¶ added in v3.0.91
func WithRequestUrlPath(requestUrlPath *string) ProxyOption
WithRequestUrlPath
PS: 如果 当前路由 和 目标路由 一致,可以不配置此项;否则必须配置.
@param requestUrlPath (1) 不带query;
(2) 可以使用 ptrKit.Of() 生成 *string 实例.
func WithScheme ¶
func WithScheme(scheme string) ProxyOption