flowcontrol

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

View Source
const FlowControlFilterName = "flowControlFilter"

FlowControlFilterName is the flow control stream filter name.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Status int    `json:"status"`
	Body   string `json:"body"`
}

Action represents the direct response of request after limited.

type Callbacks

type Callbacks interface {
	Init()
	ParseResource(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) *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)
	Exit(filter *StreamFilter)
	Enabled() bool
}

Callbacks defines the flow control callbacks

type Config

type Config struct {
	AppName      string                   `json:"app_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.FlowRule         `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.

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.

func (*DefaultCallbacks) Init

func (dc *DefaultCallbacks) Init()

Init is a no-op.

func (*DefaultCallbacks) ParseResource

func (dc *DefaultCallbacks) ParseResource(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) *ParsedResource

ParseResource parses resource from context.

type ParsedResource

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

ParsedResource contains the parsed resource wrapper and entry options.

type StreamFilter

type StreamFilter struct {
	Entry      *base.SentinelEntry
	BlockError *base.BlockError
	Callbacks  Callbacks
	// contains filtered or unexported fields
}

StreamFilter represents the flow control stream filter.

func NewStreamFilter

func NewStreamFilter(callbacks Callbacks) *StreamFilter

NewStreamFilter creates flow control filter.

func (*StreamFilter) OnDestroy

func (f *StreamFilter) OnDestroy()

OnDestroy does some exit tasks.

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)

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.

Jump to

Keyboard shortcuts

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