Documentation ¶
Index ¶
- Constants
- Variables
- func NewLimiter(options ...options.Option) middleware.MiddleWare
- func SetCPUThreshold(cPUThreshold int64) options.Option
- func SetDebug(debug bool) options.Option
- func SetEnabled(enabled bool) options.Option
- func SetRule(rule string) options.Option
- func SetWinBucket(winBucket int) options.Option
- func SetWindow(window time.Duration) options.Option
- type BBR
- type Group
- type Stat
Examples ¶
Constants ¶
View Source
const ( LimitKey = "LimitKey" LimitOp = "LimitLoad" )
Variables ¶
View Source
var LimitExceed = errors.New("509:过载保护")
Functions ¶
func NewLimiter ¶
func NewLimiter(options ...options.Option) middleware.MiddleWare
Example ¶
// 建立Group 中间件 middle := NewLimiter() // 在middleware中 // ctx中携带这两个可配置的有效数据 // 可以通过 ctx.Set // 配置获取限制器类型,可以根据不同api获取不同的限制器 ctx := context.WithValue(context.TODO(), LimitKey, "key") // 可配置成功是否上报 // 必须是 overload.Op 类型 ctx = context.WithValue(ctx, LimitOp, overload.Success) _ = middle
Output:
func SetCPUThreshold ¶
func SetEnabled ¶
func SetWinBucket ¶
Types ¶
type BBR ¶
type BBR struct {
// contains filtered or unexported fields
}
BBR 实现类似bbr的限制器.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group 表示BBRLimiter的类,并形成其中的命名空间
Click to show internal directories.
Click to hide internal directories.