mirror of
https://github.com/xiaoqidun/limit.git
synced 2025-10-11 14:30:23 +08:00
docs(微调文档): 对文档进行微调
This commit is contained in:
@@ -22,12 +22,10 @@ func main() {
|
||||
limiter := limit.New()
|
||||
// 2. 确保在程序退出前优雅地停止后台任务,这非常重要
|
||||
defer limiter.Stop()
|
||||
|
||||
// 3. 为任意键 "some-key" 获取一个速率限制器
|
||||
// - rate.Limit(2): 表示速率为 "每秒2个请求"
|
||||
// - 2: 表示桶的容量 (Burst),允许瞬时处理2个请求
|
||||
rateLimiter := limiter.Get("some-key", rate.Limit(2), 2)
|
||||
|
||||
// 4. 模拟3次连续的突发请求
|
||||
// 由于速率和容量都为2,只有前两次请求能立即成功
|
||||
for i := 0; i < 3; i++ {
|
||||
|
Reference in New Issue
Block a user