Documentation ¶
Overview ¶
Package proxy of reverse handler based fasthttp this lib ref to: Issue: https://github.com/valyala/fasthttp/issues/64 Code: https://golang.org/src/net/http/httputil/reverseproxy.go Pool Ref: https://github.com/fatih/pool/blob/master/channel.
Index ¶
- Variables
- type Factory
- type IBalancer
- type Option
- func WithAddress(addresses ...string) Option
- func WithBalancer(addrWeights map[string]Weight) Option
- func WithDebug() Option
- func WithDisablePathNormalizing(isDisablePathNormalizing bool) Option
- func WithTLS(certFile, keyFile string) Option
- func WithTLSConfig(config *tls.Config) Option
- func WithTimeout(d time.Duration) Option
- type OptionWS
- type Pool
- type Proxier
- type ReverseProxy
- type W
- type WSReverseProxy
- type Weight
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultUpgrader specifies the parameters for upgrading an HTTP // connection to a WebSocket connection. DefaultUpgrader = &websocket.FastHTTPUpgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, } // DefaultDialer is a dialer with all fields set to the default zero values. DefaultDialer = websocket.DefaultDialer )
Functions ¶
This section is empty.
Types ¶
type Factory ¶
type Factory func(string) (*ReverseProxy, error)
Factory the generator to creat ReverseProxy
type IBalancer ¶
type IBalancer interface {
Distribute() int
}
IBalancer .
func NewBalancer ¶
NewBalancer constructs a IBalancer instance which implements roundrobin algorithm.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option to define all options to reverse http proxy.
func WithAddress ¶
WithAddress generate address options
func WithBalancer ¶
WithBalancer generate balancer options
func WithDisablePathNormalizing ¶
WithDisablePathNormalizing sets whether disable path normalizing.
func WithTLS ¶
WithTLS build tls.Config with server certFile and keyFile. tlsConfig is nil as default
func WithTLSConfig ¶
func WithTimeout ¶
WithTimeout specify the timeout of each request
type OptionWS ¶
type OptionWS interface {
// contains filtered or unexported methods
}
OptionWS to define all options to reverse web socket proxy.
func WithDebug_OptionWS ¶
func WithDebug_OptionWS() OptionWS
WithDebug_OptionWS is used to enable debug mode.
func WithDialer_OptionWS ¶
WithDialer_OptionWS use specified dialer
func WithForwardHeadersHandlers_OptionWS ¶
func WithForwardHeadersHandlers_OptionWS(handler forwardHeaderHandler) OptionWS
WithForwardHeadersHandlers_OptionWS allows users to customize forward headers.
func WithURL_OptionWS ¶
WithURL_OptionWS specify the url to backend websocket server. WithURL_OptionWS("ws://YOUR_WEBSOCKET_HOST:PORT/AND/PATH")
func WithUpgrader_OptionWS ¶
func WithUpgrader_OptionWS(upgrader *websocket.FastHTTPUpgrader) OptionWS
WithUpgrader_OptionWS use specified upgrader.
type Pool ¶
type Pool interface { // Get returns a new ReverseProxy from the pool. Get(string) (*ReverseProxy, error) // Put Reseting the ReverseProxy puts it back to the Pool. Put(*ReverseProxy) error // Close closes the pool and all its connections. After Close() the pool is // no longer usable. Close() // Len returns the current number of connections of the pool. Len() int }
Pool interface ... this interface ref to: https://github.com/fatih/pool/blob/master/pool.go
type Proxier ¶
type Proxier interface { ServeHTTP(ctx *fasthttp.RequestCtx) // ? SetClient(addr string) Proxier // Reset . Reset() // Close . Close() }
Proxier can be HTTP or WebSocket proxier TODO:
type ReverseProxy ¶
type ReverseProxy struct {
// contains filtered or unexported fields
}
ReverseProxy reverse handler using fasthttp.HostClient
func NewReverseProxyWith ¶
func NewReverseProxyWith(options ...Option) (*ReverseProxy, error)
NewReverseProxyWith create an ReverseProxy with options
func (*ReverseProxy) ServeHTTP ¶
func (p *ReverseProxy) ServeHTTP(ctx *fasthttp.RequestCtx)
ServeHTTP ReverseProxy to serve ref to: https://golang.org/src/net/http/httputil/reverseproxy.go#L169
func (*ReverseProxy) SetClient ¶
func (p *ReverseProxy) SetClient(addr string) *ReverseProxy
SetClient ...
type W ¶
type W interface {
Weight() int
}
W is an interface which should be implemented by the type which will be used in balancer.
type WSReverseProxy ¶
type WSReverseProxy struct {
// contains filtered or unexported fields
}
WSReverseProxy . refer to https://github.com/koding/websocketproxy
func NewWSReverseProxyWith ¶
func NewWSReverseProxyWith(options ...OptionWS) (*WSReverseProxy, error)
NewWSReverseProxyWith constructs a new WSReverseProxy with options.
func (*WSReverseProxy) ServeHTTP ¶
func (w *WSReverseProxy) ServeHTTP(ctx *fasthttp.RequestCtx)
ServeHTTP WSReverseProxy to serve