Documentation ¶
Index ¶
- Constants
- func RegisterCallbacks(name string, cb Callbacks)
- type Action
- type Callbacks
- type Config
- type DefaultCallbacks
- func (dc *DefaultCallbacks) AfterBlock(filter *StreamFilter, ctx context.Context, headers types.HeaderMap, ...)
- func (dc *DefaultCallbacks) AfterPass(filter *StreamFilter, ctx context.Context, headers types.HeaderMap, ...)
- func (dc *DefaultCallbacks) Append(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, ...)
- func (dc *DefaultCallbacks) Enabled() bool
- func (dc *DefaultCallbacks) Exit(filter *StreamFilter)
- func (dc *DefaultCallbacks) Init()
- func (dc *DefaultCallbacks) ParseResource(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, ...) *ParsedResource
- func (dc *DefaultCallbacks) Prepare(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, ...)
- func (dc *DefaultCallbacks) ShouldIgnore(flowControlFilter *StreamFilter, ctx context.Context, headers types.HeaderMap, ...) bool
- type ParsedResource
- type StreamFilter
- func (f *StreamFilter) Append(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, ...) api.StreamFilterStatus
- func (f *StreamFilter) OnDestroy()
- func (f *StreamFilter) OnReceive(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, ...) api.StreamFilterStatus
- func (f *StreamFilter) SetReceiveFilterHandler(handler api.StreamReceiverFilterHandler)
- func (f *StreamFilter) SetSenderFilterHandler(handler api.StreamSenderFilterHandler)
- type StreamFilterFactory
Constants ¶
const (
FlowControlFilterName = "flowControlFilter"
)
FlowControlFilterName is the flow control stream filter name.
Variables ¶
This section is empty.
Functions ¶
func RegisterCallbacks ¶ added in v0.21.0
RegisterCallbacks stores customized callbacks.
Types ¶
type Callbacks ¶
type Callbacks interface { Init() ShouldIgnore(flowControlFilter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) bool Prepare(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap, trafficType base.TrafficType) ParseResource(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap, trafficType base.TrafficType) *ParsedResource AfterBlock(flowControlFilter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) AfterPass(flowControlFilter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) Append(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) Exit(filter *StreamFilter) Enabled() bool }
Callbacks defines the flow control callbacks
func GetCallbacksByConfig ¶ added in v0.21.0
GetCallbacksByName returns specified or default Callbacks.
type Config ¶
type Config struct { AppName string `json:"app_name"` CallbackName string `json:"callback_name"` LogPath string `json:"log_path"` GlobalSwitch bool `json:"global_switch"` Monitor bool `json:"monitor"` KeyType api.ProtocolResourceName `json:"limit_key_type"` Action Action `json:"action"` Rules []*flow.Rule `json:"rules"` }
Config represents the flow control configurations.
type DefaultCallbacks ¶
type DefaultCallbacks struct {
// contains filtered or unexported fields
}
DefaultCallbacks represents the default flow control filter implementation.
func (*DefaultCallbacks) AfterBlock ¶
func (dc *DefaultCallbacks) AfterBlock(filter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap)
AfterBlock sends response directly.
func (*DefaultCallbacks) AfterPass ¶
func (dc *DefaultCallbacks) AfterPass(filter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap)
AfterPass is a no-op by default.
func (*DefaultCallbacks) Append ¶ added in v0.21.0
func (dc *DefaultCallbacks) Append(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap)
Append is a no-op by default.
func (*DefaultCallbacks) Enabled ¶
func (dc *DefaultCallbacks) Enabled() bool
Enabled reports whether the callbacks enabled.
func (*DefaultCallbacks) Exit ¶
func (dc *DefaultCallbacks) Exit(filter *StreamFilter)
Exit is a no-op by default.
func (*DefaultCallbacks) ParseResource ¶
func (dc *DefaultCallbacks) ParseResource(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap, trafficType base.TrafficType) *ParsedResource
ParseResource parses Resource from context.
func (*DefaultCallbacks) Prepare ¶ added in v0.21.0
func (dc *DefaultCallbacks) Prepare(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap, trafficType base.TrafficType)
Prepare is a no-op by default.
func (*DefaultCallbacks) ShouldIgnore ¶ added in v0.21.0
func (dc *DefaultCallbacks) ShouldIgnore(flowControlFilter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) bool
ShouldIgnore is a no-op by default.
type ParsedResource ¶
type ParsedResource struct { Resource *base.ResourceWrapper Opts []sentinel.EntryOption }
ParsedResource contains the parsed Resource wrapper and entry options.
type StreamFilter ¶
type StreamFilter struct { Entry *base.SentinelEntry BlockError *base.BlockError Callbacks Callbacks ReceiverHandler api.StreamReceiverFilterHandler SenderHandler api.StreamSenderFilterHandler // contains filtered or unexported fields }
StreamFilter represents the flow control stream filter.
func NewStreamFilter ¶
func NewStreamFilter(callbacks Callbacks, trafficType base.TrafficType) *StreamFilter
NewStreamFilter creates flow control filter.
func (*StreamFilter) Append ¶ added in v0.21.0
func (f *StreamFilter) Append(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) api.StreamFilterStatus
Append will be called after request response, do nothing if request was blocked in OnReceive phase.
func (*StreamFilter) OnReceive ¶
func (f *StreamFilter) OnReceive(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) api.StreamFilterStatus
OnReceive creates resource and judges whether current request should be blocked.
func (*StreamFilter) SetReceiveFilterHandler ¶
func (f *StreamFilter) SetReceiveFilterHandler(handler api.StreamReceiverFilterHandler)
func (*StreamFilter) SetSenderFilterHandler ¶ added in v0.21.0
func (f *StreamFilter) SetSenderFilterHandler(handler api.StreamSenderFilterHandler)
type StreamFilterFactory ¶
type StreamFilterFactory struct {
// contains filtered or unexported fields
}
StreamFilterFactory represents the stream filter factory.
func (*StreamFilterFactory) CreateFilterChain ¶
func (f *StreamFilterFactory) CreateFilterChain(context context.Context, callbacks api.StreamFilterChainFactoryCallbacks)
CreateFilterChain add the flow control stream filter to filter chain.