proxyKit

package
v3.0.93 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMarked added in v3.0.71

func IsMarked(header http.Header) bool

IsMarked 此请求是否被 chimera 代理过?

@param header 请求头

func IsProxyDialError added in v3.0.23

func IsProxyDialError(err error) bool

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

func ProxyToUrl(w http.ResponseWriter, r *http.Request, targetUrl *url.URL) (err error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL