Golang Go语言中 time/rate 实现接口 - IP/账户 限流

Golang Go语言中 time/rate 实现接口 - IP/账户 限流

原文链接: https://www.douyacun.com/article/f8f4e2bb806a6176e9c61dcaa0a4a6cc

背景:

  • gin 框架,中间件
  • 博客开放好玩的 API

需求:

  • 接口限流
  • 按账户 /IP/Token 限流
  • 定时加载配置

todo:

  • 分布式限流

整理了一下 time/rate 实现原理,简化公式:

tokens (当前可用令牌数) := (now (当前时间) - last(上一次消耗令牌的时间) ).Seconds() * limit(令牌 /每秒)


更多关于Golang Go语言中 time/rate 实现接口 - IP/账户 限流的实战教程也可以访问 https://www.itying.com/category-94-b0.html

回到顶部