forwardKit

package
v3.0.903 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForwardToHost

func ForwardToHost(w http.ResponseWriter, r *http.Request, errorLog *log.Logger, host string, options ...DirectorOption) (err error)

ForwardToHost

@param errorLog 可以为nil(但不推荐这么干)

func ForwardToHostComplexly

func ForwardToHostComplexly(w http.ResponseWriter, r *http.Request, errorLog *log.Logger, transport http.RoundTripper, modifyResponse func(*http.Response) error, host string, options ...DirectorOption) (err error)

ForwardToHostComplexly

@param errorLog 可以为nil(但不推荐这么干) @param transport 可以为nil @param modifyResponse 可以为nil

func ForwardToUrl

func ForwardToUrl(w http.ResponseWriter, r *http.Request, errorLog *log.Logger, url string) (err error)

ForwardToUrl 代理请求到目标url.

@param errorLog 可以为nil,即无输出 @param url 目标url

func NewDirector

func NewDirector(targetHost string, options ...DirectorOption) (dewDirector func(req *http.Request), err error)

NewDirector

@param targetHost hostname || hostname:port

func NewSingleHostDirector

func NewSingleHostDirector(target *url.URL) (director func(req *http.Request), err error)

NewSingleHostDirector

TODO: 参考了 httputil.NewSingleHostReverseProxy,后续要实时更新(Golang版本升级).

Types

type DirectorOption

type DirectorOption func(opts *directorOptions)

func WithExtraQueryParams

func WithExtraQueryParams(extraQueryParams map[string][]string) DirectorOption

func WithOverrideQueryParams

func WithOverrideQueryParams(overrideQueryParams map[string][]string) DirectorOption

func WithRequestUrlPath

func WithRequestUrlPath(requestUrlPath string) DirectorOption

func WithScheme

func WithScheme(scheme string) DirectorOption

type ReverseProxy

type ReverseProxy struct {
	*httputil.ReverseProxy
}

func NewReverseProxy

func NewReverseProxy(director func(*http.Request), transport http.RoundTripper, modifyResponse func(*http.Response) error, errLog *log.Logger, errHandler func(http.ResponseWriter, *http.Request, error)) (*ReverseProxy, error)

NewReverseProxy

PS: 对于 httputil.ReverseProxy 结构体,Rewrite 和 Director 只能有一个非nil.

@param director 不能为nil!!! @param transport 可以为nil @param modifyResponse 可以为nil @param errLog 可以为nil @param errHandler 可以为nil

func NewSingleHostReverseProxy

func NewSingleHostReverseProxy(target *url.URL) (*ReverseProxy, error)

NewSingleHostReverseProxy

@param target 不能为nil,否则会panic

func (*ReverseProxy) Forward

func (rp *ReverseProxy) Forward(w http.ResponseWriter, r *http.Request) (err error)

Forward 代理请求.

Jump to

Keyboard shortcuts

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