limiting_strategy

package
v0.15.11 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "strategy-limiting"

Variables

View Source
var (
	ErrorLimitingRefuse = errors.New("refuse by limiting strategy")
)

Functions

func Check added in v0.9.0

func Check(cfg *Config, workers map[eosc.RequireId]eosc.IWorker) error

func Create added in v0.9.0

func Create(id, name string, v *Config, workers map[eosc.RequireId]eosc.IWorker) (eosc.IWorker, error)

func DoStrategy added in v0.9.0

func DoStrategy(ctx eocontext.EoContext, next eocontext.IChain, scalars *Scalars) error

func NewActuator

func NewActuator() *actuatorHttp

func Register

func Register(register eosc.IExtenderDriverRegister)

Register 注册http路由驱动工厂

func RegisterActuator

func RegisterActuator(handler ActuatorsHandler)

Types

type ActuatorSet

type ActuatorSet interface {
	Strategy(ctx eocontext.EoContext, next eocontext.IChain, scalars *Scalars) error
	Set(id string, limiting *LimitingHandler)
	Del(id string)
}

type ActuatorsHandler

type ActuatorsHandler interface {
	Assert(ctx eocontext.EoContext) bool
	Check(ctx eocontext.EoContext, handlers []*LimitingHandler, scalars *Scalars) error
}

type Config

type Config struct {
	Name        string                `json:"name" skip:"skip"`
	Description string                `json:"description" skip:"skip"`
	Stop        bool                  `json:"stop" label:"禁用"`
	Priority    int                   `json:"priority" label:"优先级" description:"1-999"`
	Filters     strategy.FilterConfig `json:"filters" label:"过滤规则"`
	Rule        Rule                  `json:"limiting" label:"限流规则" description:"限流规则"`
}

type Controller

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

func NewController

func NewController() *Controller

func (*Controller) AllWorkers

func (c *Controller) AllWorkers() []string

func (*Controller) Check

func (c *Controller) Check(cfg interface{}) (profession, name, driver, desc string, err error)

func (*Controller) ConfigType

func (c *Controller) ConfigType() reflect.Type

func (*Controller) Del

func (c *Controller) Del(id string)

func (*Controller) Get

func (c *Controller) Get() interface{}

func (*Controller) Mode

func (c *Controller) Mode() eosc.SettingMode

func (*Controller) Set

func (c *Controller) Set(conf interface{}) (err error)

func (*Controller) Store

func (c *Controller) Store(id string)
type Header struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Limiting

type Limiting struct {
	drivers.WorkerBase
	// contains filtered or unexported fields
}

func (*Limiting) CheckSkill

func (l *Limiting) CheckSkill(skill string) bool

func (*Limiting) Destroy

func (l *Limiting) Destroy() error

func (*Limiting) Reset

func (l *Limiting) Reset(v interface{}, workers map[eosc.RequireId]eosc.IWorker) error

func (*Limiting) Start

func (l *Limiting) Start() error

func (*Limiting) Stop

func (l *Limiting) Stop() error

type LimitingHandler

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

func NewLimitingHandler

func NewLimitingHandler(name string, conf *Config) (*LimitingHandler, error)

func (*LimitingHandler) Filter

func (l *LimitingHandler) Filter() strategy.IFilter

func (*LimitingHandler) Metrics

func (l *LimitingHandler) Metrics() metrics.Metrics

func (*LimitingHandler) Name

func (l *LimitingHandler) Name() string

func (*LimitingHandler) Priority

func (l *LimitingHandler) Priority() int

func (*LimitingHandler) Response added in v0.9.0

func (l *LimitingHandler) Response() StrategyResponseConf

func (*LimitingHandler) Stop

func (l *LimitingHandler) Stop() bool

type Rule

type Rule struct {
	Metrics  []string             `json:"metrics" label:"限流计数器名"`
	Query    Threshold            `json:"query" label:"请求限制" description:"按请求次数"`
	Traffic  Threshold            `json:"traffic" label:"流量限制" description:"按请求内容大小"`
	Response StrategyResponseConf `json:"response" label:"响应内容"`
}

type Scalars added in v0.9.0

type Scalars struct {
	QuerySecond resources.Vector
	QueryMinute resources.Vector
	QueryHour   resources.Vector

	TrafficsSecond resources.Vector
	TrafficsMinute resources.Vector
	TrafficsHour   resources.Vector
}

type Set

type Set map[string]struct{}

func (Set) Add

func (s Set) Add(key string)

func (Set) Has

func (s Set) Has(key string) bool

type StrategyResponseConf added in v0.9.0

type StrategyResponseConf struct {
	StatusCode  int       `json:"status_code" label:"HTTP状态码"`
	ContentType string    `json:"content_type" label:"Content-Type"`
	Charset     string    `json:"charset" label:"Charset"`
	Headers     []*Header `json:"header" label:"Header参数"`
	Body        string    `json:"body" label:"Body"`
}

StrategyResponseConf 策略返回内容配置

func (*StrategyResponseConf) SetBodyLabel added in v0.9.0

func (s *StrategyResponseConf) SetBodyLabel(labels map[string]string) string

type Threshold

type Threshold struct {
	Second int64 `json:"second" label:"每秒限制"`
	Minute int64 `json:"minute" label:"每分钟限制"`
	Hour   int64 `json:"hour" label:"每小时限制"`
}

type ThresholdUint

type ThresholdUint struct {
	Second int64
	Minute int64
	Hour   int64
}

Jump to

Keyboard shortcuts

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