Documentation
¶
Overview ¶
Package routerlimit provide router limit tools
Index ¶
Constants ¶
View Source
const ( // NoLimit 无限制 NoLimit int = -1 // Block 禁止 Block int = 0 )
Variables ¶
This section is empty.
Functions ¶
func StreamServerInterceptor ¶
func StreamServerInterceptor(limiter *Limiter) grpc.StreamServerInterceptor
StreamServerInterceptor returns a new stream server interceptor that performs rate limiting on the request.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(limiter *Limiter) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptors that performs request rate limiting.
Types ¶
type LimitValue ¶
type LimitValue struct { // 频次限制key Key string // 频次限制提示消息 Message string // Duration 周期 Duration time.Duration // Quota 配额 Quota int }
LimitValue the limit value
type Limiter ¶
type Limiter struct { PersistenceFn PersistenceFn Config *RouterLimit }
Limiter the limiter struct for hold fn and config
type PersistenceFn ¶
type PersistenceFn func(ctx context.Context, key string, limit int, period time.Duration, n int) (remaining int, reset time.Duration, allowed bool)
PersistenceFn the limit persistence fn for store limit status
type RouterLimit ¶
type RouterLimit struct { // 默认限制:路由下匹配 header key 做限制 Limit []Limit // 设置黑名单:当 header key value 匹配某规则时,则禁止访问 Block []KV // 默认频次控制 Default Default // 关闭频次限制 Disabled bool }
RouterLimit 路由频次限制
func (*RouterLimit) Match ¶
func (r *RouterLimit) Match(path string, header Getter) *LimitValue
Match 匹配频次限制规则
func (*RouterLimit) MatchHeader ¶
func (r *RouterLimit) MatchHeader(path string, data map[string][]string) *LimitValue
MatchHeader 匹配http header 类型
func (*RouterLimit) MatchMap ¶
func (r *RouterLimit) MatchMap(path string, data map[string]string) *LimitValue
MatchMap 匹配Map类型
Click to show internal directories.
Click to hide internal directories.