middleware

package
v0.0.0-...-dca265f Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2018 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DomainHandler     = 1
	DomainPathHandler = 2
)
View Source
const (
	XForwardedFor = "X-Forwarded-For"
	XRealIP       = "X-Real-IP"
)
View Source
const (
	LbRandom           = "RANDOM"
	LbRoundRobin       = "ROUNDROBIN"
	LbWeightRoundRobin = "WEIGHTROUNDROBIN"
)

Variables

This section is empty.

Functions

func CreateMwChain

func CreateMwChain(domain *core.Domain) http.Handler

func CreatePathMwChain

func CreatePathMwChain(domain *core.Domain, path *core.Path) http.Handler

Types

type Base

type Base struct {
	HandlerType int8
	Domain      *core.Domain
	Path        *core.Path
	// contains filtered or unexported fields
}

func (*Base) GetDomain

func (mw *Base) GetDomain() *core.Domain

func (*Base) GetHandlerType

func (mw *Base) GetHandlerType() int8

func (*Base) GetLb

func (mw *Base) GetLb() lb.LoadBalance

func (*Base) GetLmt

func (mw *Base) GetLmt() *limiter.Limiter

func (*Base) GetMt

func (mw *Base) GetMt() *core.Metrics

func (*Base) GetPath

func (mw *Base) GetPath() *core.Path

func (*Base) Init

func (mw *Base) Init() func(http.Handler) http.Handler

func (*Base) SetDomain

func (mw *Base) SetDomain(d *core.Domain)

func (*Base) SetHandlerType

func (mw *Base) SetHandlerType(i int8)

func (*Base) SetLb

func (mw *Base) SetLb(l lb.LoadBalance)

func (*Base) SetLmt

func (mw *Base) SetLmt(lmt *limiter.Limiter)

func (*Base) SetMt

func (mw *Base) SetMt(mt *core.Metrics)

func (*Base) SetPath

func (mw *Base) SetPath(p *core.Path)

type Baser

type Baser interface {
	GetHandlerType() int8
	GetDomain() *core.Domain
	GetPath() *core.Path
	GetLb() lb.LoadBalance
	GetLmt() *limiter.Limiter
	GetMt() *core.Metrics
	SetHandlerType(int8)
	SetDomain(*core.Domain)
	SetPath(*core.Path)
	SetLb(lb.LoadBalance)
	SetLmt(*limiter.Limiter)
	SetMt(*core.Metrics)
}

type BlackIpsMw

type BlackIpsMw struct {
	Baser
}

func (*BlackIpsMw) Init

func (mw *BlackIpsMw) Init() func(http.Handler) http.Handler

type BreakerMw

type BreakerMw struct {
	Baser
}

func (*BreakerMw) Init

func (mw *BreakerMw) Init() func(http.Handler) http.Handler

type BufferPool

type BufferPool interface {
	Get() []byte
	Put([]byte)
}

A BufferPool is an interface for getting and returning temporary byte slices for use by io.CopyBuffer.

type GateWay

type GateWay struct {
	Baser
}

func (*GateWay) Init

func (p *GateWay) Init()

func (*GateWay) ServeHTTP

func (p *GateWay) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type HgwMiddleWare

type HgwMiddleWare interface {
	Init() func(http.Handler) http.Handler
}

type LoggerMw

type LoggerMw struct {
	Baser
}

func (*LoggerMw) Init

func (mw *LoggerMw) Init() func(http.Handler) http.Handler

type MetricsMw

type MetricsMw struct {
	Baser
}

func (*MetricsMw) Init

func (mw *MetricsMw) Init() func(http.Handler) http.Handler

type RateLimiterMw

type RateLimiterMw struct {
	Baser
}

func (*RateLimiterMw) Init

func (mw *RateLimiterMw) Init() func(http.Handler) http.Handler

type RecoverMw

type RecoverMw struct {
	Baser
}

func (*RecoverMw) Init

func (mw *RecoverMw) Init() func(http.Handler) http.Handler

type RequestCopyMw

type RequestCopyMw struct {
	Baser
}

func (*RequestCopyMw) Init

func (mw *RequestCopyMw) Init() func(http.Handler) http.Handler

type ReverseProxy

type ReverseProxy struct {
	// Director must be a function which modifies
	// the request into a new request to be sent
	// using Transport. Its response is then copied
	// back to the original client unmodified.
	// Director must not access the provided Request
	// after returning.
	Director func(*http.Request)

	// The transport used to perform proxy requests.
	// If nil, http.DefaultTransport is used.
	Transport http.RoundTripper

	// FlushInterval specifies the flush interval
	// to flush to the client while copying the
	// response body.
	// If zero, no periodic flushing is done.
	FlushInterval time.Duration

	// ErrorLog specifies an optional logger for errors
	// that occur when attempting to proxy the request.
	// If nil, logging goes to os.Stderr via the log package's
	// standard logger.
	ErrorLog *log.Logger

	// BufferPool optionally specifies a buffer pool to
	// get byte slices for use by io.CopyBuffer when
	// copying HTTP response bodies.
	BufferPool BufferPool

	// ModifyResponse is an optional function that modifies the
	// Response from the backend. It is called if the backend
	// returns a response at all, with any HTTP status code.
	// If the backend is unreachable, the optional ErrorHandler is
	// called without any call to ModifyResponse.
	//
	// If ModifyResponse returns an error, ErrorHandler is called
	// with its error value. If ErrorHandler is nil, its default
	// implementation is used.
	ModifyResponse func(*http.Response) error

	// ErrorHandler is an optional function that handles errors
	// reaching the backend or errors from ModifyResponse.
	//
	// If nil, the default is to log the provided error and return
	// a 502 Status Bad Gateway response.
	ErrorHandler func(http.ResponseWriter, *http.Request, error)

	SuccessHandler func(http.ResponseWriter, *http.Request)
}

ReverseProxy is an HTTP Handler that takes an incoming request and sends it to another server, proxying the response back to the client.

func NewSingleHostReverseProxy

func NewSingleHostReverseProxy(target *url.URL, path *core.Path) *ReverseProxy

NewSingleHostReverseProxy returns a new ReverseProxy that routes URLs to the scheme, host, and base path provided in target. If the target's path is "/base" and the incoming request was for "/dir", the target request will be for /base/dir. NewSingleHostReverseProxy does not rewrite the Host header. To rewrite Host headers, use ReverseProxy directly with a custom Director policy.

func (*ReverseProxy) ServeHTTP

func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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