proxy

package
v2.0.0-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2018 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FilterHTTPAccess access log filter
	FilterHTTPAccess = "HTTP-ACCESS"
	// FilterHeader header filter
	FilterHeader = "HEADER" // process header fiter
	// FilterXForward xforward fiter
	FilterXForward = "XFORWARD"
	// FilterBlackList blacklist filter
	FilterBlackList = "BLACKLIST"
	// FilterWhiteList whitelist filter
	FilterWhiteList = "WHITELIST"
	// FilterAnalysis analysis filter
	FilterAnalysis = "ANALYSIS"
	// FilterRateLimiting limit filter
	FilterRateLimiting = "RATE-LIMITING"
	// FilterCircuitBreake circuit breake filter
	FilterCircuitBreake = "CIRCUIT-BREAKER"
	// FilterValidation validation request filter
	FilterValidation = "VALIDATION"
)
View Source
const (
	// RateBase base rate
	RateBase = 100
)

Variables

View Source
var (
	// ErrCircuitClose server is in circuit close
	ErrCircuitClose = errors.New("server is in circuit close")
	// ErrCircuitHalf server is in circuit half
	ErrCircuitHalf = errors.New("server is in circuit half")
	// ErrCircuitHalfLimited server is in circuit half, traffic limit
	ErrCircuitHalfLimited = errors.New("server is in circuit half, traffic limit")
)
View Source
var (
	// ErrPrefixRequestCancel user cancel request error
	ErrPrefixRequestCancel = "request canceled"
	// ErrNoServer no server
	ErrNoServer = errors.New("has no server")
	// ErrRewriteNotMatch rewrite not match request url
	ErrRewriteNotMatch = errors.New("rewrite not match request url")
)
View Source
var (
	// MergeContentType merge operation using content-type
	MergeContentType = "application/json; charset=utf-8"
	// MergeRemoveHeaders merge operation need to remove headers
	MergeRemoveHeaders = []string{
		"Content-Length",
		"Content-Type",
		"Date",
	}
)
View Source
var (
	// ErrBlacklist target ip in black list
	ErrBlacklist = errors.New("Err, target ip in black list")
)
View Source
var (
	// ErrTraffixLimited traffic limit
	ErrTraffixLimited = errors.New("traffic limit")
)
View Source
var (
	// ErrUnknownFilter unknown filter error
	ErrUnknownFilter = errors.New("unknow filter")
)
View Source
var (
	// ErrValidationFailure validation failure
	ErrValidationFailure = errors.New("request validation failure")
)
View Source
var (
	// ErrWhitelist target ip not in in white list
	ErrWhitelist = errors.New("Err, target ip not in in white list")
)

Functions

func GetRealClientIP

func GetRealClientIP(ctx *fasthttp.RequestCtx) string

GetRealClientIP get read client ip

Types

type AccessFilter

type AccessFilter struct {
	filter.BaseFilter
}

AccessFilter record the http access log log format: $remoteip "$method $path" $code "$agent" $svr $cost

func (*AccessFilter) Init

func (f *AccessFilter) Init(cfg string) error

Init init filter

func (*AccessFilter) Name

func (f *AccessFilter) Name() string

Name return name of this filter

func (*AccessFilter) Post

func (f *AccessFilter) Post(c filter.Context) (statusCode int, err error)

Post execute after proxy

type AnalysisFilter

type AnalysisFilter struct {
	filter.BaseFilter
}

AnalysisFilter analysis filter

func (*AnalysisFilter) Init

func (f *AnalysisFilter) Init(cfg string) error

Init init filter

func (*AnalysisFilter) Name

func (f *AnalysisFilter) Name() string

Name return name of this filter

func (*AnalysisFilter) Post

func (f *AnalysisFilter) Post(c filter.Context) (statusCode int, err error)

Post execute after proxy

func (*AnalysisFilter) PostErr

func (f *AnalysisFilter) PostErr(c filter.Context)

PostErr execute proxy has errors

func (*AnalysisFilter) Pre

func (f *AnalysisFilter) Pre(c filter.Context) (statusCode int, err error)

Pre execute before proxy

type BlackListFilter

type BlackListFilter struct {
	filter.BaseFilter
}

BlackListFilter blacklist filter

func (*BlackListFilter) Init

func (f *BlackListFilter) Init(cfg string) error

Init init filter

func (*BlackListFilter) Name

func (f *BlackListFilter) Name() string

Name return name of this filter

func (*BlackListFilter) Pre

func (f *BlackListFilter) Pre(c filter.Context) (statusCode int, err error)

Pre execute before proxy

type Cfg

type Cfg struct {
	Addr      string
	AddrRPC   string
	AddrStore string
	AddrPPROF string
	Namespace string
	TTLProxy  int64
	Filers    []*FilterSpec

	Option *Option
}

Cfg proxy config

func (*Cfg) AddFilter

func (c *Cfg) AddFilter(filter *FilterSpec)

AddFilter add a filter

type CircuitBreakeFilter

type CircuitBreakeFilter struct {
	filter.BaseFilter
}

CircuitBreakeFilter CircuitBreakeFilter

func (*CircuitBreakeFilter) Init

func (f *CircuitBreakeFilter) Init(cfg string) error

Init init filter

func (*CircuitBreakeFilter) Name

func (f *CircuitBreakeFilter) Name() string

Name return name of this filter

func (*CircuitBreakeFilter) Post

func (f *CircuitBreakeFilter) Post(c filter.Context) (statusCode int, err error)

Post execute after proxy

func (*CircuitBreakeFilter) PostErr

func (f *CircuitBreakeFilter) PostErr(c filter.Context)

PostErr execute proxy has errors

func (*CircuitBreakeFilter) Pre

func (f *CircuitBreakeFilter) Pre(c filter.Context) (statusCode int, err error)

Pre execute before proxy

type FilterSpec

type FilterSpec struct {
	Name               string `json:"name"`
	External           bool   `json:"external,omitempty"`
	ExternalPluginFile string `json:"externalPluginFile,omitempty"`
	ExternalCfg        string `json:"externalCfg,omitempty"`
}

FilterSpec filter spec

func ParseFilter

func ParseFilter(filter string) (*FilterSpec, error)

ParseFilter returns a filter

type HeadersFilter

type HeadersFilter struct {
	filter.BaseFilter
}

HeadersFilter HeadersFilter

func (*HeadersFilter) Init

func (f *HeadersFilter) Init(cfg string) error

Init init filter

func (*HeadersFilter) Name

func (f *HeadersFilter) Name() string

Name return name of this filter

func (*HeadersFilter) Post

func (f *HeadersFilter) Post(c filter.Context) (statusCode int, err error)

Post execute after proxy

func (*HeadersFilter) Pre

func (f *HeadersFilter) Pre(c filter.Context) (statusCode int, err error)

Pre execute before proxy

type Option

type Option struct {
	LimitCountDispatchWorker   uint64
	LimitCountCopyWorker       uint64
	LimitCountHeathCheckWorker int
	LimitCountConn             int
	LimitIntervalHeathCheck    time.Duration
	LimitDurationConnKeepalive time.Duration
	LimitDurationConnIdle      time.Duration
	LimitTimeoutWrite          time.Duration
	LimitTimeoutRead           time.Duration
	LimitBufferRead            int
	LimitBufferWrite           int
	LimitBytesBody             int
}

Option proxy option

type Proxy

type Proxy struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Proxy Proxy

func NewProxy

func NewProxy(cfg *Cfg) *Proxy

NewProxy create a new proxy

func (*Proxy) ReverseProxyHandler

func (p *Proxy) ReverseProxyHandler(ctx *fasthttp.RequestCtx)

ReverseProxyHandler http reverse handler

func (*Proxy) Start

func (p *Proxy) Start()

Start start proxy

func (*Proxy) Stop

func (p *Proxy) Stop()

Stop stop the proxy

type RateLimitingFilter

type RateLimitingFilter struct {
	filter.BaseFilter
}

RateLimitingFilter RateLimitingFilter

func (*RateLimitingFilter) Init

func (f *RateLimitingFilter) Init(cfg string) error

Init init filter

func (*RateLimitingFilter) Name

func (f *RateLimitingFilter) Name() string

Name return name of this filter

func (*RateLimitingFilter) Pre

func (f *RateLimitingFilter) Pre(c filter.Context) (statusCode int, err error)

Pre execute before proxy

type ValidationFilter

type ValidationFilter struct {
	filter.BaseFilter
}

ValidationFilter validation request

func (*ValidationFilter) Init

func (f *ValidationFilter) Init(cfg string) error

Init init filter

func (*ValidationFilter) Name

func (f *ValidationFilter) Name() string

Name return name of this filter

func (*ValidationFilter) Pre

func (f *ValidationFilter) Pre(c filter.Context) (statusCode int, err error)

Pre pre filter, before proxy reuqest

type WhiteListFilter

type WhiteListFilter struct {
	filter.BaseFilter
}

WhiteListFilter whitelist filter

func (*WhiteListFilter) Init

func (f *WhiteListFilter) Init(cfg string) error

Init init filter

func (*WhiteListFilter) Name

func (f *WhiteListFilter) Name() string

Name return name of this filter

func (*WhiteListFilter) Pre

func (f *WhiteListFilter) Pre(c filter.Context) (statusCode int, err error)

Pre execute before proxy

type XForwardForFilter

type XForwardForFilter struct {
	filter.BaseFilter
}

XForwardForFilter XForwardForFilter

func (*XForwardForFilter) Init

func (f *XForwardForFilter) Init(cfg string) error

Init init filter

func (*XForwardForFilter) Name

func (f *XForwardForFilter) Name() string

Name return name of this filter

func (*XForwardForFilter) Pre

func (f *XForwardForFilter) Pre(c filter.Context) (statusCode int, err error)

Pre execute before proxy

Jump to

Keyboard shortcuts

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