Documentation ¶
Index ¶
Constants ¶
View Source
const (
PluginName = "token-bucket"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APILimitConfig ¶
type APILimitConfig struct { // 系统是否开启API限流 Open bool `mapstructure:"open"` // 配置规则集合 Rules []*RateLimitRule `mapstructure:"rules"` // 每个接口的单独配置 Apis []*APILimitInfo `mapstructure:"apis"` }
APILimitConfig api限流配置
type APILimitInfo ¶
type APILimitInfo struct { // 接口名,比如对于HTTP,就是:方法+URL Name string `mapstructure:"name"` // 限制规则名 Rule string `mapstructure:"rule"` }
APILimitInfo 每个接口的单独配置信息
type BucketRatelimit ¶
type BucketRatelimit struct { // 是否开启限流 Open bool `mapstructure:"open"` // 令牌桶大小 Bucket int `mapstructure:"bucket"` // 每秒加入的令牌数 Rate int `mapstructure:"rate"` }
BucketRatelimit 针对令牌桶的具体配置
type Config ¶
type Config struct { // 是否启用远程配置,默认false。TODO 暂时无远程配置,后续版本补全 RemoteConf bool `mapstructure:"remote-conf"` // IP限流相关配置 IPLimitConf *ResourceLimitConfig `mapstructure:"ip-limit"` // 接口限流相关配置 APILimitConf *APILimitConfig `mapstructure:"api-limit"` // 基于实例的限流配置 InstanceLimitConf *ResourceLimitConfig `mapstructure:"instance-limit"` }
Config 限流配置类
type RateLimitRule ¶
type RateLimitRule struct { // 规则名 Name string `mapstructure:"name"` // 规则的限制 Limit *BucketRatelimit `mapstructure:"limit"` }
RateLimitRule 限流规则
type ResourceLimitConfig ¶
type ResourceLimitConfig struct { // 是否开启instance限流 Open bool `mapstructure:"open"` // 全局限制规则,只有一条规则 Global *BucketRatelimit `mapstructure:"global"` // 本地缓存最大多少个instance的限制器 MaxResourceCacheAmount int `mapstructure:"resource-cache-amount"` // 白名单 WhiteList []string `mapstructure:"white-list"` }
ResourceLimitConfig 基于资源的限流配置 资源可以是:IP,实例,服务等
Click to show internal directories.
Click to hide internal directories.