Documentation ¶
Index ¶
- Variables
- func AccessLog() app.HandlerFunc
- func ClientMiddleware(next endpoint.Endpoint) endpoint.Endpoint
- func CommonMiddleware(next endpoint.Endpoint) endpoint.Endpoint
- func ServerMiddleware(next endpoint.Endpoint) endpoint.Endpoint
- func TLSSupportMiddleware(host string) gin.HandlerFunc
- func TokenAuthMiddleware(jwt jwt.JWT, skipRoutes ...string) app.HandlerFunc
- func TokenLimitMiddleware() app.HandlerFunc
- type TokenBucket
- type TokenBuckets
Constants ¶
This section is empty.
Variables ¶
View Source
var (
CurrentLimiter = MakeTokenBuckets(int64(limiterCapacity), int64(limiterRate)) // 后续用redis缓存每个token对应的令牌桶
)
对每个token限流,不管它请求的API
Functions ¶
func AccessLog ¶
func AccessLog() app.HandlerFunc
func ClientMiddleware ¶
ClientMiddleware client middleware print server address 、rpc timeout and connection timeout 相当于对Endpoint进行包装,在调用前输出一些信息
func ServerMiddleware ¶
ServerMiddleware server middleware print client address
func TLSSupportMiddleware ¶
func TLSSupportMiddleware(host string) gin.HandlerFunc
func TokenAuthMiddleware ¶
func TokenAuthMiddleware(jwt jwt.JWT, skipRoutes ...string) app.HandlerFunc
func TokenLimitMiddleware ¶
func TokenLimitMiddleware() app.HandlerFunc
限流中间件,使用令牌桶的方式处理请求。Note: auth中间件需在其前面
Types ¶
type TokenBucket ¶
type TokenBucket struct { Rate int64 // 固定的token放入速率,r/s Capacity int64 // 桶的容量 Tokens int64 // 桶中当前token数量 LastTokenSec int64 // 桶上次放token的时间 // contains filtered or unexported fields }
func MakeTokenBucket ¶
func MakeTokenBucket(c, r int64) *TokenBucket
func (*TokenBucket) Allow ¶
func (tb *TokenBucket) Allow() bool
type TokenBuckets ¶
type TokenBuckets struct {
// contains filtered or unexported fields
}
func MakeTokenBuckets ¶
func MakeTokenBuckets(capacity, rate int64) *TokenBuckets
func (*TokenBuckets) Allow ¶
func (tbs *TokenBuckets) Allow(token string) bool
Click to show internal directories.
Click to hide internal directories.