filter

package
v1.0.1-rc1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDubboFilterPlugin

func RegisterDubboFilterPlugin(f DubboFilterPlugin)

RegisterDubboFilterPlugin registers dubbo filter.

func RegisterHttpFilter

func RegisterHttpFilter(f HttpFilterPlugin)

Register registers filter plugin.

func RegisterNetworkFilterPlugin

func RegisterNetworkFilterPlugin(f NetworkFilterPlugin)

RegisterNetworkFilter registers network filter.

Types

type DubboFilter

type DubboFilter interface {
	// Handle rpc invocation
	Handle(ctx *dubbo.RpcContext) FilterStatus
}

DubboFilter describe dubbo filter

type DubboFilterPlugin

type DubboFilterPlugin interface {
	// Kind returns the unique kind name to represent itself.
	Kind() string
	// CreateFilter return the filter callback
	CreateFilter(config interface{}) (DubboFilter, error)
	// Config Expose the config so that Filter Manger can inject it, so it must be a pointer
	Config() interface{}
}

NetworkFilter describe dubbo filter plugin

func GetDubboFilterPlugin

func GetDubboFilterPlugin(kind string) (DubboFilterPlugin, error)

GetDubboFilterPlugin get plugin by kind

type EmptyNetworkFilter

type EmptyNetworkFilter struct{}

EmptyNetworkFilter default empty network filter adapter which offers empty function implements

func (*EmptyNetworkFilter) OnData

func (enf *EmptyNetworkFilter) OnData(data interface{}) (interface{}, error)

OnData receive data from listener

func (*EmptyNetworkFilter) OnDecode

func (enf *EmptyNetworkFilter) OnDecode(data []byte) (interface{}, int, error)

OnDecode empty implement

func (*EmptyNetworkFilter) OnEncode

func (enf *EmptyNetworkFilter) OnEncode(p interface{}) ([]byte, error)

OnEncode empty implement

func (*EmptyNetworkFilter) OnTripleData

func (enf *EmptyNetworkFilter) OnTripleData(ctx context.Context, methodName string, arguments []interface{}) (interface{}, error)

OnTripleData empty implement

func (*EmptyNetworkFilter) ServeHTTP

ServeHTTP empty implement

type FilterChain

type FilterChain interface {
	AppendDecodeFilters(f ...HttpDecodeFilter)
	AppendEncodeFilters(f ...HttpEncodeFilter)

	OnDecode(ctx *http.HttpContext)
	OnEncode(ctx *http.HttpContext)
}

FilterChain

func NewDefaultFilterChain

func NewDefaultFilterChain() FilterChain

type FilterManager

type FilterManager struct {
	// contains filtered or unexported fields
}

FilterManager manage filters

func NewEmptyFilterManager

func NewEmptyFilterManager() *FilterManager

NewEmptyFilterManager create empty filter manager

func NewFilterManager

func NewFilterManager(fs []*model.HTTPFilter) *FilterManager

NewFilterManager create filter manager

func (*FilterManager) Apply

func (fm *FilterManager) Apply(name string, conf map[string]interface{}) (HttpFilterFactory, error)

Apply return a new filter factory by name & conf

func (*FilterManager) CreateFilterChain

func (fm *FilterManager) CreateFilterChain(ctx *http.HttpContext) FilterChain

func (*FilterManager) GetFactory

func (fm *FilterManager) GetFactory() []*HttpFilterFactory

GetFactory get all filter from manager

func (*FilterManager) Load

func (fm *FilterManager) Load()

Load the filter from config

func (*FilterManager) ReLoad

func (fm *FilterManager) ReLoad(filters []*model.HTTPFilter)

ReLoad filter configs

type FilterStatus

type FilterStatus int
const (
	Continue FilterStatus = iota
	Stop
)

type HttpDecodeFilter

type HttpDecodeFilter interface {
	Decode(ctx *http.HttpContext) FilterStatus
}

HttpDecodeFilter before invoke upstream, like add/remove Header, route mutation etc..

if config like this: - A - B - C decode filters will be invoked in the config order: A、B、C, and decode filters will be invoked in the reverse order: C、B、A

type HttpEncodeFilter

type HttpEncodeFilter interface {
	Encode(ctx *http.HttpContext) FilterStatus
}

HttpEncodeFilter after invoke upstream, decode filters will be invoked in the reverse order

type HttpFilterFactory

type HttpFilterFactory interface {
	// Config Expose the config so that Filter Manger can inject it, so it must be a pointer
	Config() interface{}

	// Apply After the config is injected, check it or make it to default
	Apply() error

	// PrepareFilterChain create filter and append it to FilterChain
	//
	// Be Careful !!! Do not pass the Factory's config pointer to the Filter instance,
	// Factory's config may be updated by FilterManager
	PrepareFilterChain(ctx *http.HttpContext, chain FilterChain) error
}

HttpFilterFactory describe http filter

type HttpFilterPlugin

type HttpFilterPlugin interface {
	// Kind returns the unique kind name to represent itself.
	Kind() string

	// CreateFilterFactory return the filter factory
	CreateFilterFactory() (HttpFilterFactory, error)
}

HttpFilterPlugin describe plugin

func GetHttpFilterPlugin

func GetHttpFilterPlugin(kind string) (HttpFilterPlugin, error)

GetHttpFilterPlugin get plugin by kind

type NetworkFilter

type NetworkFilter interface {
	// ServeHTTP handle http request and response
	ServeHTTP(w stdHttp.ResponseWriter, r *stdHttp.Request)
	// OnDecode decode bytes received from getty server
	OnDecode(data []byte) (interface{}, int, error)
	// OnEncode encode interface sent to getty server
	OnEncode(p interface{}) ([]byte, error)
	// OnData dubbo rpc invocation from getty server
	OnData(data interface{}) (interface{}, error)
	// OnTripleData triple rpc invocation from triple-server
	OnTripleData(ctx context.Context, methodName string, arguments []interface{}) (interface{}, error)
}

NetworkFilter describe network filter

type NetworkFilterPlugin

type NetworkFilterPlugin interface {
	// Kind returns the unique kind name to represent itself.
	Kind() string
	// CreateFilterFactory return the filter callback
	CreateFilter(config interface{}) (NetworkFilter, error)
	// Config Expose the config so that Filter Manger can inject it, so it must be a pointer
	Config() interface{}
}

NetworkFilter describe network filter plugin

func GetNetworkFilterPlugin

func GetNetworkFilterPlugin(kind string) (NetworkFilterPlugin, error)

GetNetworkFilterPlugin get plugin by kind

Jump to

Keyboard shortcuts

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